I have a custom post type called 'Podcasts' but none of the posts are showing in the archive widget. Only the main query (blog posts) are being shown.
I've tried adding this code below to include the Podcasts posts, but this only allowed them to show up in the archive template, which is great but not quite there yet.
/* Show Podcasts posts in archive */
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item','post','podcasts');
$query->set('post_type',$post_type);
return $query;
}
}
How can I get the Podcasts posts to show up in the archive widget?
Edit: For clarity, I'm talking about when I click the dropdown in the native archives widget. The days/months that should have podcast posts don't even show up. Only the day/months for the blog posts show.
Edit 2: I tried dropping this into functions.php
and now the months containing the podcasts posts show up, but when I click on those months, it just leads me to the 404 WordPress template. However, when I click on a month containing a post from the main query, it takes me to the archive
template listing those posts.
add_filter( 'getarchives_where', 'custom_getarchives_where' );
function custom_getarchives_where( $where ){
$where = str_replace( "post_type = 'post'", "post_type IN ( 'post', 'podcasts' )", $where );
return $clauses;
}
pre_get_posts
to include the post type in archive pages.