Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am trying to set up an image menu to show "all posts", "all videos" (custom post type: rich_media). I want to have an individual image for each post type, and by clicking it I want to show all posts in the current category of the chosen post type.

All post_types share the common categories taxonomy.

I managed to list all regular posts from current category by simply linking to current category, not sure how to do the trick with the custom post.

share|improve this question
add comment

1 Answer

function add_post_type_to_archives($query) {
    if(is_archive() and empty($query->query_vars['suppress_filters'])){
        $query->set('post_type', array('post', 'rich_media'));
    }
    return $query;
}
add_filter('pre_get_posts', 'add_post_type_to_archives');

For a custom post type to be shown in archives, it needs to be added to the $query. Like above. It's up to you to refine the situations where you want it added. Like:

if(!empty($query->query_vars['custom_tag_query_var'])){
    $query->set('post_type', array('post', 'rich_media'));
}

This will add the rich_media post type to the loop if the *custom_tag_query_var* is present (custom_tag_query_var archive).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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