[Resolved] Page Header for archive page with custom posts

Home Forums Support [Resolved] Page Header for archive page with custom posts

Home Forums Support Page Header for archive page with custom posts

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #953474
    Roger

    Hi, I’ve created a custom post type of ‘hunt’ using the following code:

    if ( ! function_exists( 'create_post_type' ) ) :
    
    function create_post_type() {
        
        register_post_type( 'hunt', 
            array(
                'labels' => array(
                    'name' => __( 'Hunts' ), 
                    'singular_name' => __( 'Hunt' ), 
                ),
                'public' => true,
                'supports' => array ( 'title', 'editor', 'custom-fields', 'page-attributes', 'thumbnail', 'excerpt' ), // do you need all of these options?
                'taxonomies' => array( 'category', 'post_tag' ), 
                'hierarchical' => true,
                'menu_icon' => get_bloginfo( 'template_directory' ) . "/images/icon.png",
                'rewrite' => array ( 'slug' => __( 'hunts' ) ) 
            )
        );
    
    }
    add_action( 'init', 'create_post_type' );
    
    endif;

    And I’ve added the following filter so that this custom post type appears on the category page along with standard posts:

    add_filter('pre_get_posts', 'query_post_type');
    function query_post_type($query) {
      if( is_category() || is_tag()) {
        $post_type = get_query_var('post_type');
        if($post_type)
            $post_type = $post_type;
        else
            $post_type = array('nav_menu_item', 'post', 'hunt');
        $query->set('post_type',$post_type);
        return $query;
        }
    }

    However, I’ve now lost the styling for the archive page that I set in the customizer and, the header element isn’t being applied to the custom post type. What am I doing wrong?

    #954156
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. What kind of styling? Columns? If so, this might help: https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type

    2. In the Display Rules for the Header Element, have you included your new post type?

    #954186
    Roger

    Hi Tom,

    1. Yes – the column settings that I’ve applied to the category page for standard posts and that I want to apply to the category page for my custom posts are as follows:

    column settings

    I’ve added the filter that you suggest but nothing has changed.

    2. Yes, I’ve set it to display on the category archive for the custom post, but nothing is appearing.

    Element display settings

    #954428
    Tom
    Lead Developer
    Lead Developer

    1. That filter is needed. Did you update the name of the cpt to look for?

    2. Can you try “Hunt Category Archive” instead? That Display Rule will target single posts inside that category.

    #954439
    Roger

    Hi Tom,

    1. Yes, I updated the cpt name, but it’s not working

    2. I’ve changed the display location for the element to Hunt Category Archive, but still no joy.

    I noticed that although in the Element itself it shows that ‘Hunt Category Archive’ has been selected, on the summary page for all Elements it shows ‘Post Category Archive’ which might suggest some sort of conflict/error.

    Display Location in the Element itself:

    All Elements list view:
    null

    #955094
    Tom
    Lead Developer
    Lead Developer

    So it looks like you’re using a regular category taxonomy. What happens if you choose “Vancouver” along with “Post Category Archive”?

    #955163
    Roger

    Just gave that a try. Changing ‘Hunt Category Archive’ to ‘Post Category Archive’ in the Header Element fails to display the Header too.

    #955538
    Tom
    Lead Developer
    Lead Developer

    Hmm, what is happening here..

    What if you create a custom taxonomy for that CPT instead of using post categories?

    #956206
    Roger

    Ok. I created a custom taxonomy of ‘Cities’ for that CPT and set the Header Element to display for ‘Hunt City Archive – All Cities’ and we have lift off! Not sure why Elements didn’t like the combined taxonomy, but this will be fine.

    I also adjusted the column filter and that’s all sorted too:

    add_filter( 'generate_blog_columns','tu_portfolio_columns' );
    function tu_portfolio_columns( $columns ) {
        if ( is_tax() ) {
            return true;
        }
    
        return $columns;
    }

    Thanks for help troubleshooting ๐Ÿ™‚

    #956328
    Tom
    Lead Developer
    Lead Developer

    Strange, I’ll look into it.

    Glad it’s all working now ๐Ÿ™‚

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.