• I need to include events in the normal category pages that I am also using for normal posts (i.e. not the special event categories).
    I managed to add the normal categories to the event custom post type easily:

    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 displayed the normal category checkboxes fine in wp-admin.

    I then added the pre_get_posts hook as follows, to show them in the category page. However, for some reason, this does not work with event post types.

    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;
      }
    }

    What could be the reason for this? Is it maybe because the custom post type event doesn’t have the has_archive flag true? (If not can I turn it on in any way?) Is there any other reason for this not to work? It seems like the standard way to include other post types in category pages.

    Thanks.

    https://wordpress.org/plugins/events-manager/

  • The topic ‘Including events in normal category pages’ is closed to new replies.