Header vanishers on category pages using custom post types

  • MeMeMe

    #51719

    I am using the graphefe theme with no changes, except for two snippets of code in functions.php. (I’ll post the code below)

    The first snippet adds custom posts so they show up in the front page (blog type), and on this code the header displays correctly.

    The second snippet changes it so that custom post types also show up in a category archive page, if they are marked with that category.

    But now whenever a category archive page is visited, the header completely vanishes and is not displayed.

    The code snippets: the first one which just affects the blog front page and works fine:

    /**
     * Show Custom Post Types in flow
     
     *
     */
    add_filter( 'pre_get_posts', 'my_get_posts' );
    
    function my_get_posts( $query ) {
    
    if ( ( is_home() && $query->is_main_query() ) || is_feed() )
    
    		$query->set( 'post_type', array( 'post', 'toy', 'place' ) );
    
    return $query;
    }
    

    The second snippet, that sets up archive views

    /**
     * 
     * Show Custom Post Types in Category archives
     
     *
     */
    add_filter('pre_get_posts', 'query_post_type');
    function query_post_type($query) {
      if( is_category() ) {
        $post_type = get_query_var('post_type');
        if($post_type)
            $post_type = $post_type;
        else
            $post_type = array('nav_menu_item', 'post', 'toy', 'place'); // don't forget nav_menu_item to allow menus to work!
        $query->set('post_type',$post_type);
        return $query;
        }
    }
    

    The archives are populated properly, but with this code snippet in place, the header vanishes when going to any category page, even if there are no custom post types in that archive.

    How can I restore the visibility of the header?

Viewing 1 post (of 1 total)

  • You must be logged in to reply to this topic.
Graphene Themes Forum