How to share category taxonomy with custom post type (The Event Calendar plugin)

You can use register_taxonomy_for_object_type() to use a taxonomy with a post type, without having to touch the post type registration code, example:

function wpa_categories_for_events(){
    register_taxonomy_for_object_type( 'category', 'tribe_events' );
}
add_action( 'init', 'wpa_categories_for_events' );

To have events appear on the category pages, I believe you have to modify the default category queries via pre_get_posts to add custom post types, by default they only query the post post type.

function wpa_events_on_category_pages( $query ) {
    if ( $query->is_category() && $query->is_main_query() ) {
        $query->set( 'post_type', array( 'post', 'tribe_events' ) );
    }
}
add_action( 'pre_get_posts', 'wpa_events_on_category_pages' );

Leave a Comment