I'm new here and my english isn't perfect so I'm sorry for this :) I'm here because I'm workin on site with post list sorted by category and I have problem with sort out my posts in categories and children categories under them. Now everything is messed up. I would like to sort my custom posts like that:
CATEGORY 1
CHILD CATEGORY 1
- Post
- Post
- Post
CHILD CATEGORY2
- Post
- Post
- Post
CATEGORY 2
- CHILD CATEGORY3
- Post
- Post
- Post
CATEGORY 3
- Post
Post
CHILD CATEGORY4
- Post
- Post
- Post
Is it possible with this code:
<?php
$querystr = "SELECT terms.* FROM $wpdb->term_taxonomy tax LEFT JOIN $wpdb->terms terms ON tax.term_id = terms.term_id WHERE tax.taxonomy = 'MY_CUSTOM_TAXONOMY'";
$categories = $wpdb->get_results($querystr, OBJECT);
foreach( $categories as $category ):
echo '<div class="category-header"><h3>'.$category->name.'</h3>';
echo '<p class="category-description">'.strip_tags(term_description($category->term_id,'MY_CUSTOM_TAXONOMY')).'</p></div>';
$posts = get_posts( array( 'MY_CUSTOM_TAXONOMY' => $category->name, 'post_type' => 'MY_CUSTOM_POST' ) );
foreach($posts as $post) :
setup_postdata($post);
the_title();
endforeach;
endforeach;
?>
I will be grateful for all help, thank You!!