I have a custom post type called “videos” that I want to include in the Archives widget (stock widget in the TwentyTwelve theme). It DOES already appear on the archives page, but just not in the widget.
I already have
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
function add_my_post_types_to_query( $query ) {
if ( $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'videos' ) );
return $query;
}
in functions.php – can I modify the IF statement to be something like “if main query OR archive widget query”? How can I do this?
The Archive widget is using
wp_get_archives()
to display the archive.If you want to target all the
wp_get_archives()
functions, you can use thegetarchives_where
filter to add your custom post type:If you want to target only the first Archive widget, you can try
with
where the filter is removed, to prevent affecting other parts.
It worked for me: