Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Blog settings not being applied for a custom post type archive

  • I have two CPTs, testimonials and portfolio-new. I have applied some different blog settings for their archives.

    // Portfolio and Testimonial archives
    add_filter( 'generate_blog_get_column_count','gm_custom_column_count' );
    function gm_custom_column_count( $count ) {
        if ( is_post_type_archive( 'testimonial' ) || is_post_type_archive( 'portfolio-new' ) ) {
            return 33;
        }
    
        return $count;
    }
    
    add_filter( 'generate_blog_masonry','gm_testimonial_masonry' );
    function gm_testimonial_masonry( $masonry ) {
        if ( is_post_type_archive( 'testimonial' ) ) {
            return 'true';
        }
    
        return $masonry;
    }
    
    add_filter( 'option_generate_blog_settings', 'gm_custom_featured_column_page_settings' );
    function gm_custom_featured_column_page_settings( $options ) {
        if ( is_post_type_archive( 'testimonial' ) || is_post_type_archive( 'portfolio-new' ) ) {
            $options['featured_column'] = false;
        }
      
        return $options;
    }

    The both have a content template assigned, a separate one for each. I only see the testimonial archive in columns, though, the portfolio-new displays one post below the other, no columns. I have cleared permalinks, no cache on the site, it’s a local install.

    What could be the issue?

  • Update: if I include conditional for the portfolio-new CPT for the masonry filter, it seems to work, columns are displayed but I obviously don’t want masonry layout for the portfolio-new CPT.

    add_filter( 'generate_blog_masonry','gm_custom_masonry' );
    function gm_custom_masonry( $masonry ) {
        if ( is_post_type_archive( 'testimonial' ) || is_post_type_archive( 'portfolio-new' ) ) {
            return 'true';
        }
    
        return $masonry;
    }
  • Hi George,

    For columns to work, you need to enable the columns first before setting columns number:
    https://docs.generatepress.com/article/option_generate_blog_settings/#options-%E2%80%98column_layout%E2%80%99

  • It’s already set in the blog settings, I don’t think I need to set it again. Anyway, I tried the following, no change.

    add_filter( 'generate_blog_get_column_count','gm_custom_column_count' );
    function gm_custom_column_count( $count ) {
        if ( is_post_type_archive( 'testimonial' ) || is_post_type_archive( 'portfolio-new' ) ) {
            return 33;
        }
    
        return $count;
    }
    
    add_filter( 'option_generate_blog_settings', 'gm_custom_column_page_settings' );
    function gm_custom_column_page_settings( $options ) {
        if ( is_post_type_archive( 'testimonial' ) || is_post_type_archive( 'portfolio-new' ) ) {
            $options['column_layout'] = true;
            $options['featured_column'] = false;
        }
      
        return $options;
    }
    
    add_filter( 'generate_blog_masonry','gm_testimonial_masonry' );
    function gm_testimonial_masonry( $masonry ) {
        if ( is_post_type_archive( 'testimonial' )  ) {
            return 'true';
        }
    
        return $masonry;
    }

    As I said, columns are displayed for the testimonial CPT.

  • I need to see your site’s backend.

  • See attached. Blog filters are towards the bottom. Archives can be accessed from the top.

  • Your solution here seems to be working. Not sure why it works for the testimonials, though, since I haven’t applied the generate_blog_columns filter for the testimonial CPT.

  • So it means the page doesn’t meet the condition of is_post_type_archive('portfolio-new').

    I guess you have to use this condition in this case: 'portfolio-new' === get_post_type() && ! is_singular()

  • Both CPTs should not have been set to display columns since columns have been set from the Customizer and columns should display by default on their archives. I have not set the columns to appear for the testimonial CPT in any other place but I get columns for it. For the portfolio-new CPT, I had to use the generate_blog_columns filter in order to get columns. I shouldn’t need to do that, that’s what I mean.

  • Both CPTs should not have been set to display columns since columns have been set from the Customizer and columns should display by default on their archives.

    GP does not know about the CPTs, you need to use the filter to tell it.

    So if you remove all those filters, the testimonial archive still gets columns?

  • No, it doesn’t but it does when the generate_blog_masonry filter for that CPT is used! Very strange…

  • Ok, I think when masonry filter is used to enable masonry, columns seems to get applied automatically which makes sense, I guess.

    Thanks for looking into it!

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