• i’m using this plugin along with some code to display (query) all the custom posts (CPT: “menu”) on a page, grouped together by the custom taxonomy: “menucategory”.
    • the custom tax (menucategory) is hierarchical, and i would like these items grouped together

    the test page is here:
    https://viatransferdev.tracyappsdesign.com/menu/

    here’s the code for that page:

    <?php $terms = get_terms('menucategory');
      	$count = count($terms); ?>
      		<?php if ($count > 0) {
      			foreach ( $terms as $term) { ?>
    
      			<h2 class="menuCategoryTitle"><?php echo $term->name; ?></h2>
    			<div class="menuCategory">
      				<?php $loop = new WP_Query(array('menucategory' => $term->slug, 'post_type' => menu, 'orderby' => custom_sort, 'order' => ASC));
                				while ( $loop->have_posts() ) : $loop->the_post(); ?>
      						<div class="menuItem">
      							<h3><?php the_title(); ?></h3>
      							<?php the_content(); ?>
      						</div><!--/menuItem-->
      					<?php endwhile; ?>
      			</div><!--/menuCategory-->
      		<?php }
      	} ?>

    and this is how the hierarchy of the custom tax is set up: (the “order” value will be in parentheses)

    • Pizza (1)
    • Traditional Pizzas (10)
    • Specialty Pizzas (20)
    • Appetizers (10)

    (i number by 10’s so that if the client wants to add a category between 2 and 3 (of like, 20) all the others after don’t need to be renumbered as well)

    is this a bug? something wrong with my code? or am i misunderstanding how the plugin works?

    thanks!

    https://www.ads-software.com/extend/plugins/custom-taxonomy-sort/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter tracy apps

    (@tray)

    with further troubleshooting, i found that the code i was using wasn’t even responding to any sorting. so i replaced it with the following code, and i’m still getting the same issue. the PARENT taxonomy is showing the posts within all their CHILDREN taxonomy.

    new code:

    <?php $categories = get_terms('menucategory', 'orderby=custom_sort&order=ASC&hide_empty=true&hierarchical=true');
    foreach( $categories as $category ):
    ?>
    	<h2 class="menuCategoryTitle"><?php echo $category->name; ?></h2>
    
    	<?php
    		$posts = get_posts(array(
    			'post_type' => 'menu',
    			'taxonomy' => $category->taxonomy,
    			'term' => $category->slug,
    			'nopaging' => true,
    			));
    			foreach($posts as $post):
    			setup_postdata($post); ?>
    
    			<div class="menuItem">
    				<h3><?php the_title(); ?></h3>
    				<?php the_content(); ?>
    			</div><!--/menuItem-->
    
    	<?php endforeach; ?>
      <?php endforeach; ?>

    what i need is for the page to display all the posts (CPT: “menu”), grouped by taxonomy (“menucategory”), BUT when the taxonomy has a parent, the parent should just display the title, then the child taxonomies listed below (still with the CPT posts grouped within each)

    is this even possible? i really have a hard time believing this should be this difficult!

    Thread Starter tracy apps

    (@tray)

    just to clarify, what i want is the page to display like this:

    Pizza
    Traditional Pizzas

    • Italian Sausage Pizza…
    • Cheese Pizza…

    Specialty Pizzas

    • Stacy’s Special…

    Appetizers

    • Bruschetta Tradizionale
    • Cheese Plate
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘hierarchical taxonomy not sorted correctly within hierarchy’ is closed to new replies.