Site logo

Archived topic

Columns on archive page for custom post types

3 replies · Started by Bandara on April 9, 2021

Viewing posts 1–4 of 4

Hello!

I wanted to display my custom post types in columns on the archive page. I tried putting this code that I found on this page: https://docs.generatepress.com/article/using-columns-in-the-blog/

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

    return $columns;
}

But it didn't work.

Then I found this code on this support post: https://generatepress.com/forums/topic/cant-divide-custom-post-types-in-columns/#post-1707854

add_filter( 'generate_blog_columns', function( $columns ) {
    if ( 'podcast' === get_post_type() && ! is_singular() ) {
        return true;
    }

    return $columns;
} );

And that worked. I'm wondering what's going on since the first code from the KB article seems like it should have worked. If it works for me, is it fine to keep the second code?

Thanks!

Hi there,

the second code is perfectly fine and correct to use.
The first code may not have work if the archive slug did not match correctly.

Thanks!

I just realized that I didn't clarify that I was trying to do this for the tag archive page, not the full blog page.

I have the same custom post slug in both codes, so I wouldn't have thought that could be the problem.

Any way, thanks for taking a look.

It sounds like the issue is you're not displaying a custom post type archive but displaying a custom post type in a taxonomy archive. Which in that case the 2nd code is the correct method.

Glad to be of help.

This archived topic is closed to new replies.