I want to have a custom post type, named event
, listed with normal posts in the category pages.
I have managed to add categories easily to the custom post type with this:
add_action('init', 'add_category_boxes');
add_action('plugins_loaded','add_category_boxes');
function add_category_boxes()
{
register_taxonomy_for_object_type('category', 'event');
}
This displays the category checkboxes in wp-admin and works fine. I have then followed the approach here (also suggested elsewhere), as follows:
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query)
{
if(is_category() && $query->is_main_query())
{
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','event');
$query->set('post_type',$post_type);
return $query;
}
}
But the posts of type event
still don't come up in the respective category pages.
What could be the reason for this? Do I need to add anything else?
The event
post types are actually coming from the Events Manager plugin. I don't know if there is something special about these which is stopping them from being displayed in the category pages.