0

For the last two days I tried to loop through a parent category and display my custom post type posts within it.

I've created a custom post type with the name: mentors_post_type and participants_post_type, where I use category as a taxonomy.

'taxonomies' => array( 'category', 'post_tag' ),

Both post types are organized in categories for each year: 2016, 2017, 2018, etc. Somehow I can't achieve to loop through the years category and display the posts and sub-categories like:

(year category)
2017 (subcategory)
all posts with custom post type: mentors_post_type 
2016 (subcategory)
all posts with custom post type: mentors_post_type 

No matter how I've tried it, I don't get any posts from the custom post type or all posts from the custom post type (can't filter them by category). When I just get the category names and their post-counts, the post-counts are right.

1

1 Answer 1

-1

You would do something along these lines using the category id, and an array of the post_types within your loop

query_posts( array(
 'post_type' => array( 'post', 'report', 'opinion', bookmark' ),
 'cat' => 3,
 'orderby' => 'date',
 'order' => 'DESC',
 'showposts' => 5 )
 );

Hope that helps

2
  • Never use query_posts() - wordpress.stackexchange.com/q/50761/22728 Commented Feb 1, 2017 at 10:12
  • thanks to booth of you! i'm pretty sure i've tried it that way… but now it works. great! thanks a lot! but is there a way to seperate the child-categories? i need the title of the child-category and a single ul for the posts. Commented Feb 1, 2017 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.