[Resolved] Masonry fails on category archive after adding CPT

Home Forums Support Masonry fails on category archive after adding CPT

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1022949
    Joshua Vandercar

    I have a CPT to which I’ve added support for the default WP category taxonomy. I’m able to successfully add those CPT posts to post queries on the front end (including the category archives) by use of the this code:

    add_action( 'pre_get_posts', function ( $query ) {
    
          if ( ! is_admin() && $query->is_main_query() )
             $query->set( 'post_type', array( 'post', 'typewheel_snippet' ) );
    
          return $query;
    
       } );

    However, doing so, makes the masonry fail on these archive pages. I’ve not been able to pinpoint why this is. I appreciate any leads. Thanks!

    #1023295
    David
    Staff
    Customer Support

    Hi there,

    have you tried the blog options filter and setting masonry specifically for that post type:

    https://docs.generatepress.com/article/option_generate_blog_settings/

    #1023619
    Joshua Vandercar

    Tried that and it was already returning the proper options for both post and typewheel_snippet. I did find a fix, though, using the generate_blog_masonry filter here.

    This code works:

    add_filter( 'generate_blog_masonry', function ( $masonry ) {
    
       if ( is_archive() )
          return true;
    
       return $masonry;
    
    } );
    #1023663
    David
    Staff
    Customer Support

    Awesome – glad you found the solution.

    #1023664
    Joshua Vandercar

    It was weird. Prior to that, the masonry was being applied to articles of type post, but not to the CPT. Thus, the archive was partial mosaic, but those posts were hidden behind the ones not getting it applied. Happy to have a fix! Thanks for pointing me to the docs again.

    #1023794
    David
    Staff
    Customer Support

    Not something i have experienced – but the masonry option can be a little funky.
    Glad to be of help.

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