How to add a link(href) so when i click it, it renders (shows all) posts of custom post type (rich_media), from the current category?

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.

Read More

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.

Related posts

Leave a Reply

1 comment

  1. 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).