I'm trying to create a plugin which adds a new custom post type and it should be shown at the same locations as a normal post (front page, archives etc.).
Is there any functions for me to retrieve the post types which are currently being called in the query so that I can modify and add my CPT to the current query? (example stated in 2nd comment if my question sounds confusing)
I can't use the code below (i.e. list the post types) because I can't predict what post types would the user have :
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'page', 'album', 'movie', 'quote' ) );
return $query;
}
Similarly, I can't use the code below because that would return all post types, including those which might not be intended to be shown at the front page :
if ( !is_admin() && empty( $query->query_vars['suppress_filters'] ) && $query->is_main_query() ) {
$post_type = get_query_var('post_type');
$post_types = get_post_types( array( 'public' => true ) );
if ($post_type) {
$post_type = $post_type;
} else {
$post_type = $post_types;
}
$query->set('post_type',$post_type);
return $query;
}
}
So, is there any ideas how I can add my CPT to the query without affecting other post types? Thanks for helping!