[Resolved] Custom Post Type – can't get columns to work

Home Forums Support [Resolved] Custom Post Type – can't get columns to work

Home Forums Support Custom Post Type – can't get columns to work

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1035132
    Simon

    Hi Generate Press Team,

    Big fan of your theme. I have a problem that I hope you can help with.

    I have a site that is using a Custom Post Type (boats).

    I am trying to get the Custom Post Type to appear in columns on the archive page for that post type, in the same way that the ‘normal’ post types do.

    I have ‘normal’ posts set to columns-2 and that works fine. But the custom post type (boats) still shows as one column.

    I have found the filter that you supply to fix this, but I can’t get it to work. I am using the Code Snippets plugin as you recommend.

    I am using the following snippet of PHP to get the custom post type (boats) to ‘show’ on the website. This worked fine.

    ==========

    function namespace_add_custom_types( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {
    $query->set( ‘post_type’, array(
    ‘post’, ‘nav_menu_item’, ‘boats’
    ));
    return $query;
    }
    }
    add_filter( ‘pre_get_posts’, ‘namespace_add_custom_types’ );

    ===========

    I have also added the following filter from the Generate Press website. With a few changes so that it refers to my custom post type. But it doesn’t generate columns.

    ===========

    add_filter( ‘generate_blog_columns’,’sf_boats_columns’ );
    function sf_boats_columns( $columns ) {
    if ( is_post_type_archive( ‘boats’ ) ) {
    return true;
    }

    return $columns;
    }

    ===========

    I have de-activated all plugins and tried switching theme, still doesn’t work.

    The site is being developed locally so I cannot share a url.

    Thank you for any help with this.

    PS. Just had a thought. The archive pages I am trying to get to display in Columns are all actually Category archives within a Custom Post Type. Rather than just the archive of the parent Custom Post Type.

    eg: Custom Post Type = ‘boats’. Categories within ‘boats’ = ‘bluewater-cruiser’, ‘centreboard’ etc.
    It is the category archive page that I am trying to target with the make columns filter. So I need ‘bluewater-cruiser’ archive to be in columns. I hope that is clear. Thanks again for any help.

    #1035494
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Your code looks good:

    add_filter( 'generate_blog_columns', function( $columns ) {
        if ( is_post_type_archive( 'boats' ) ) {
            return true;
        }
    
        return $columns;
    } );

    I would need to actually see the site in order to figure out what’s going on. Any chance you can put it up on a temp live server quickly?

    #1035503
    Simon

    Thank you for your swift reply Tom. I will see if I can ‘make it live’ briefly and get back to you.

    #1035603
    Simon

    Hi Tom, I have put the site up on a subdomain. How do I supply you with url, username and password? Thank you again for this. GeneratePress rocks!

    #1035684
    David
    Staff
    Customer Support

    Hi there,

    you can send the URL and login info via the Account Issue form:

    https://generatepress.com/contact/

    Please add the URL for this topic to the form so we can track.

    #1037415
    Tom
    Lead Developer
    Lead Developer

    It seems you need to target categories and tags, instead of a cpt archive.

    Let’s try this:

    add_filter( 'generate_blog_columns', function( $columns ) {
        $targets = array(
            'bluewater-cruiser',
            'centreboard',
        );
    
        if ( is_archive( $targets ) ) {
            return true;
        }
    
        return $columns;
    } );

    You just need to add more items to the $targets array.

    Let me know if you need more info 🙂

    #1037897
    Simon

    Thank you Tom.
    Works perfectly.
    You have made my day.

    #1038330
    Tom
    Lead Developer
    Lead Developer

    Glad I could help! 🙂

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