Site logo

Archived topic

Masonry fails on category archive after adding CPT

5 replies · Started by Joshua Vandercar on September 30, 2019

Viewing posts 1–6 of 6

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!

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;

} );

Awesome - glad you found the solution.

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.

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

This archived topic is closed to new replies.