Support » Fixing WordPress » Tag archive with multiple post types => breaks nav

  • Resolved Bill Erickson


    I’ve created multiple post types (Events, Videos, Publications…) and in the register_post_type() function for each I’ve set ‘taxonomies’ => array(‘post_tag’). This puts the Tag taxonomy on all post types. The goal is to have tag archive pages that show content from all post types. I’m also using a custom WordPress menu with a link to a page and custom links to the post type archive pages.

    By default, WordPress only displays posts from the ‘post’ post type on tag archive pages. I’m running this in my functions.php file to fix it:

    /* All Posts in Tag Archives */
    add_filter('pre_get_posts', 'bcrw_tag_query');
    function bcrw_tag_query($query) {
      if(is_tag()) {
        $post_type = get_query_var('post_type');
    	    $post_type = $post_type;
    	    $post_type = array('post','event', 'videos', 'publications', 'podcasts');
    	return $query;

    When this filter is disabled, the tag archive displays no results (there’s no posts in the ‘post’ post type with that tag) and the WordPress menu works. When the filter is enabled, posts from all post types are displayed correctly, but the nav menu disappears.

    Menu working:
    Menu not working:

    I’ve also tried changing the above function from $post_type = array(‘post’,’event’, ‘videos’, ‘publications’, ‘podcasts’); to $post_type = ‘all’, thinking maybe it didn’t work with arrays. I get the same result (correct posts show up, nav menu doesn’t).

    1. Am I approaching this wrong? Is there a better way to make tag pages show all post types?
    2. Why is the nav menu dependent upon a single post type in query_vars?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Tag archive with multiple post types => breaks nav’ is closed to new replies.