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?

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

Leave a Comment