Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter acrocosm

    (@acrocosm)

    Thanks for the reply. I come from drupal, I’m used in having build-in or at least free tools for basic CMS functionality. I’ll write down what worked for me and the issues I faced for someone else that may be interested:

    I found out how to get a drop down filled with the terms of my custom taxonomy.

    
    $terms = get_terms( array(
    	'taxonomy' => 'my_custom_taxonomy',
    	'hide_empty' => false,
    ) );
    $select_terms = "<select name='option-term' id='option-term' class='postform'>n";
    $select_terms.= "<option value='-1'>All</option>n";
    foreach($terms as $terms){
    	if($terms->count > 0){
    		$select_terms.= "<option value='".$terms->slug."'>".$terms->name."</option>";
    	}
    }
    $select_terms.= "</select>";
    echo $select_terms;
    

    Then made a display posts shortcode that would include categories in the class list. I had to make custom slugs since the site is non-latin and I couldn’t get it to display the classes correctly.

    
    category_display="my_custom_taxonomy" category_label=" " post_type="my_custom_post_type" taxonomy="my_custom_taxonomy" tax_term="" content_class="dps-listing-content"
    

    Along with this piece of code I found from you 🙂 in functions.php

    
    /**
     * Display Posts Shortcode, add category classes
     * @see https://displayposts.com/2019/01/03/add-category-classes/
     */
    function be_dps_add_category_classes( $classes ) {
      $categories = get_the_terms( get_the_ID(), 'my_custom_taxonomy' );
      if( ! empty( $categories ) && ! is_wp_error( $categories ) ) {
        foreach( $categories as $category ) {
          $classes[] = 'cat-' . $category->slug;
        }
      }
      return $classes;
    }
    add_filter( 'display_posts_shortcode_post_class', 'be_dps_add_category_classes' );
    

    Then used jquery to filter the list of posts DP made for me. Since each item had its term as a class it wasn’t hard to write the code for it.

    Now I need to group the drop down options hierarchically and figure out how to make a template for the linked pages since I require a 2 level hierarchy for the products. I also wonder how this will all work out when I’ll have to convert it to a multilingual site. But I guess all that is irrelevant, so…

    • This reply was modified 6 years, 6 months ago by acrocosm.
    • This reply was modified 6 years, 6 months ago by acrocosm.

    Yes, read on…

    I made with CPT-UI a custom post called “product_pi” and assigned a custom taxonomy named “product_categories_pi”. Then assigned some terms to my posts from this taxonomy one of them is “fridges”.

    Then in my display posts shortcode I used the following to select only fridges:
    category_display="product_categories_pi" category_label="" post_type="product_pi" taxonomy="product_categories_pi" tax_term="fridges"

    This will give me only “fridges” and nothing else

    (I left the label blank so I can show just a dashicon with css)

    Good luck

Viewing 2 replies - 1 through 2 (of 2 total)