• I have this code that works fine but the problem is with the ordering of the displayed data. Now it is little disorder and posts are duplicated when you check subcategory position. What can I do to display a tree of categories with posts included in each category and subcategory, for example:

    <h1>Prime Category 1</h1>

    • Post 1
    • Post 2

      <h2>Sub Category 1</h2>

    • Post 1
    • Post 2
      <h2>Sub Category 2</h2>
    • Post 1
      <h1>Prime Category 2</h1>
      <h2>Sub Category</h2>
    • Post 1
    • Post 1

      this is my code:

      <?php
      
      // List posts by the terms for a custom taxonomy of any post type
      
      $post_type = 'biblioteka';
      $tax = 'kategoria-pozycji';
      $tax_terms = get_terms( $tax );
      if ($tax_terms) {
      	foreach ($tax_terms  as $tax_term) {
      
      	$args = array(
      
      		'post_type' => $post_type,
      		'child_of' => $tax_term->term_id,
      		"$tax" => $tax_term->slug,
      		'post_status' => 'publish',
      		'posts_per_page' => 2,
      		'hierarchical' => true,
      		'caller_get_posts'=> 1
      
      );
      
      	$my_query = null;
      	$my_query = new WP_Query($args);
      
      		if( $my_query->have_posts() ) : ?>
      
      			<h1><?php echo $tax_term->name; ?></h2>
      
      			<ul>
      			<?php while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
      
      				<li id="post-<?php the_ID(); ?>">
      					<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
      				</li>
      
      			<?php endwhile; // end of loop ?>
      
      			</ul>
      
      		<?php else : ?>
      		<?php endif; // if have_posts()
      		wp_reset_query();
      
      	}
      }
      ?>

      I will be greatful for all help

  • The topic ‘Custom taxonomy list with children and post included’ is closed to new replies.