Home › Forums › Pro Support › Preserve Masonry when using facets to search posts
- This topic has 17 replies, 2 voices, and was last updated 4 years, 1 month ago by
Heidi.
-
AuthorPosts
-
March 21, 2019 at 12:40 pm #8304
Heidi
ParticipantI’m using GeneratePress, WP Show Posts and FacetsWP to create a searchable posts page.
https://couchfilmcollective.org/hire-us/
I’m using masonry, but when I search any facet, the masonry stops working– any idea on to keep the masonry working when searching?
Thanks so much as always!
March 21, 2019 at 4:15 pm #8307Tom
KeymasterHi there,
We likely need to reload masonry once FacetWP does its thing. Can you ask them if there’s a JS trigger we can use to reload masonry?
Let me know 🙂
March 21, 2019 at 4:35 pm #8308Heidi
ParticipantA quick search on FacetWP shows that you are correct. I’ve asked them the question and also found some examples, but I am not sure which of these would apply best to WP Show Posts:
https://gist.facetwp.com/?_keywords=masonryMarch 22, 2019 at 2:18 pm #8321Heidi
ParticipantAccording to FacetWP help desk, masonry or other js scripts that need to reload can be done on the facetwp-loaded js hook
https://facetwp.com/documentation/developers/javascript/facetwp-loaded/However, I have no Javascript skills. I’ve tried this, but it doesn’t work:
<script> jQuery(document).on('facetwp-loaded', function() { jQuery( '.masonry-container' ).masonry( 'layout' ); }); </script>
Any better ideas? Much thanks!
March 22, 2019 at 4:32 pm #8323Tom
KeymasterLet’s try this:
<script> jQuery( document ).on( 'facetwp-loaded', function() { jQuery( '.wp-show-posts-masonry' ).masonry( 'layout' ); } ); </script>
Let me know 🙂
March 22, 2019 at 6:26 pm #8329Heidi
ParticipantNo luck, but could certainly be user error on my part. I’m putting the script in Elements– wp_footer and I’ve checked execute PHP, with a display rule of entire site. Is that correct?
Screenshot of Element:
https://couchfilmcollective.org/wp-content/uploads/Screen-Shot-2019-03-22-at-6.16.06-PM.pngScreenshot of a facet search with the masonry not quite working right:
https://couchfilmcollective.org/wp-content/uploads/Screen-Shot-2019-03-22-at-6.25.19-PM.pngAppreciate your help, Tom!
March 23, 2019 at 5:14 pm #8337Tom
KeymasterLooks good – you don’t need to execute PHP in this case though.
Can we try this?:
<script> jQuery( document ).on( 'facetwp-loaded', function() { console.log( 'loaded!' ); jQuery( '.wp-show-posts-masonry' ).masonry( 'layout' ); } ); </script>
Now right click your page, click “Inspect” and go to the “Console” tab. Then load FacetWP – does the word “loaded!” appear in the console?
March 23, 2019 at 7:02 pm #8338Heidi
ParticipantI tried that, and I do see “loaded!”, but still not working. It does show an error “cannot call methods on masonry prior to initialization; attempted to call ‘layout'”
Here’s a screenshot of the full console:
https://couchfilmcollective.org/wp-content/uploads/Screen-Shot-2019-03-23-at-7.00.04-PM.pngMarch 24, 2019 at 5:15 pm #8348Tom
KeymasterAh, so that code is firing before the core masonry code. Can you try giving your Hook Element a high priority? Something like
100
maybe?March 25, 2019 at 9:53 pm #8368Heidi
ParticipantI tried adding a priority of 100, but still not working. Same error. Addition things I can try? Grateful for any ideas…also happy to send you admin access if you want to try some things in real time.
March 26, 2019 at 3:00 pm #8374Tom
KeymasterLet’s try one more thing before I go in to check it out:
<script> jQuery( document ).on( 'facetwp-loaded', function() { var container = jQuery( '.wp-show-posts-masonry' ); container.imagesLoaded( function() { container.masonry( 'layout' ); } ); } ); </script>
March 26, 2019 at 3:48 pm #8376Heidi
ParticipantError is gone, but still not working….
March 26, 2019 at 4:47 pm #8380Tom
KeymasterAh, hopefully we’re close. Feel free to send me temp admin login details and I’ll take a look: https://wpshowposts.com/contact/
March 26, 2019 at 9:21 pm #8382Heidi
ParticipantI’ve sent it via message– thanks for your help!
March 27, 2019 at 5:16 pm #8396Tom
KeymasterBeen playing with it, but still no luck. It’s like masonry isn’t firing even though the trigger is. I wonder if FacetWP has a masonry-specific example of how to use their trigger?
-
AuthorPosts
- You must be logged in to reply to this topic.