Display events with default category.

I'm using Events+ and have added some code so that I can add events to default post categories. This works fine, however when I go to view the category page my event is not listed
This is the code that I have added to my functions.php file // use post categories for events

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

function wpa_tags_for_events(){
register_taxonomy_for_object_type( 'post_tag', 'incsub_event' );
}
add_action( 'init', 'wpa_tags_for_events' );

// unset default event categories
add_action( 'init', 'unregister_cats' );
function unregister_cats() {
unregister_taxonomy_for_object_type( 'eab_events_category', 'incsub_event' );
}
add_action( 'init', 'unregister_tags' );
function unregister_tags() {
unregister_taxonomy_for_object_type( 'tags', 'incsub_event' );
}
    Ivan

    Hi nifty !

    You can try to add the following code

    function wpmu_add_incsub_event_to_category_page( $query ) {
        if( is_category() ) {
            $post_types = $query->get( 'post_type' );
            if ( empty( $post_types ) || !is_array( $post_types ) ) {
                $post_types =  array( 'post' );
            }
            $post_types[] = 'incsub_event';
            $query->set( 'post_type', $post_types );
            return $query;
        }
    }
    add_filter( 'pre_get_posts', 'wpmu_add_incsub_event_to_category_page' );

    Also, for applying CSS-styles from Event+ for the category pages you can add this code

    function wpmu_add_event_style_to_category_page() {
        if ( is_category() ) {
            wp_enqueue_style('eab_front');
        }
    }
    add_action('wp_print_styles', 'wpmu_add_event_style_to_category_page');

    Best regards,
    Ivan.

    Ivan

    Hi nifty !

    I mean - to add my code to your code, don't replace

    Also, you can make shorter your code like this

    <?php
    
    function wpmu_event_change_to_default_categories(){
        register_taxonomy_for_object_type( 'category', 'incsub_event' );
        register_taxonomy_for_object_type( 'post_tag', 'incsub_event' );
        unregister_taxonomy_for_object_type( 'eab_events_category', 'incsub_event' );
        unregister_taxonomy_for_object_type( 'tags', 'incsub_event' );
    }
    add_action( 'init', 'wpmu_event_change_to_default_categories' );

    Best regards,
    Ivan.

    nifty

    Thanks Ivan

    I have added your code in and replaced my code with the new code that you provided. When I try to view one of the categories that has events in it I get the following error -

    Fatal error: Uncaught Error: [] operator not supported for strings in /home/devnifty/public_html/enctest.co.uk/wp-content/themes/silversparkle/functions.php:88 Stack trace: #0 /home/devnifty/public_html/enctest.co.uk/wp-includes/class-wp-hook.php(298): wpmu_add_incsub_event_to_category_page(Object(WP_Query)) #1 /home/devnifty/public_html/enctest.co.uk/wp-includes/class-wp-hook.php(323): WP_Hook->apply_filters(NULL, Array) #2 /home/devnifty/public_html/enctest.co.uk/wp-includes/plugin.php(515): WP_Hook->do_action(Array) #3 /home/devnifty/public_html/enctest.co.uk/wp-includes/class-wp-query.php(1681): do_action_ref_array('pre_get_posts', Array) #4 /home/devnifty/public_html/enctest.co.uk/wp-includes/class-wp-query.php(3238): WP_Query->get_posts() #5 /home/devnifty/public_html/enctest.co.uk/wp-includes/class-wp-query.php(3347): WP_Query->query(Array) #6 /home/devnifty/public_html/enctest.co.uk/wp-content/themes/Extra/includes/layouts.php(127): WP_Query->__construct(Array) #7 /home/devnifty/public_html/enctest.co.uk/wp-conten in /home/devnifty/public_html/enctest.co.uk/wp-content/themes/silversparkle/functions.php on line 88

    Ivan

    Also, I think it will be better using this version of the code for that

    function wpmu_add_incsub_event_to_category_page( $query ) {
        if( is_category() ) {
            $post_types = $query->get( 'post_type' );
            if ( !is_array( $post_types ) ) {
                if( !is_string( $post_types ) ) {
                    $post_types =  array( 'post' );
                } else {
                    $post_types = (array) ( ( '' === $post_types ) ? 'post' : $post_types );
                }
            }
            $post_types[] = 'incsub_event';
            $query->set( 'post_type', $post_types );
            return $query;
        }
    }
    add_filter( 'pre_get_posts', 'wpmu_add_incsub_event_to_category_page' );

    Best regards,
    Ivan.