Tagged: drag and drop, masonry, sort order
-
AuthorPosts
-
February 3, 2022 at 11:55 am #1338669
Greetings,
we currently have a weird problem.
Some time ago, we had problems displaying masonries. See here = https://kriesi.at/support/topic/masonry-grid-shows-entries-more-than-once/It was fixed by this code, provided by you: https://kriesi.at/support/topic/randomise-posts-in-category-page/#post-1331323
The code above was for the “Referenzen” Masonry.Now we realised that no matter how we arrange our “Leistungen” masonry gallery, it always stays the same order.
First I deployed the hot fix to be able to drag and drop the order, provided here: https://kriesi.at/support/topic/gallery-drag-and-drop-sort/#post-1337989This code works, and I’m able to order the entries as needed, but on the frontend the order stays the same.
Once I remove this codeif (!session_id()) { session_start(); } function edit_posts_orderby($orderby_statement) { $seed = $_SESSION['seed']; if (empty($seed)) { $seed = rand(); $_SESSION['seed'] = $seed; } $orderby_statement = 'RAND('.$seed.')'; return $orderby_statement; } add_filter('posts_orderby', 'edit_posts_orderby');
the order applies but the our “Referenzen” masonry doesnt work as intended.
Is there somehow a way to exclude or split the functionality of each others masonry?
As always, thanks in advance!
February 7, 2022 at 3:37 am #1339253Hey emilconsor,
Thank you for the inquiry.
the order applies but the our “Referenzen” masonry doesnt work as intended.
Have you tried implementing a condition (e.g is_page, is_singular) to the posts_orderby filter so that it only applies on a specific page? Are the masonry elements located on the same page? Please note that the changes in the posts_orderby filter will be applied on every posts element in the page or any elements that executes a WordPress posts query.
// https://developer.wordpress.org/reference/hooks/posts_orderby/
Best regards,
IsmaelFebruary 7, 2022 at 5:52 pm #1339415Hi Ismael,
thanks for the response!
Yes, unfortunetly both masonries are on the same page.
If we could fix our original problem (Load More Button Shows Infinite Entries), we could remove this Code that inferes with our masonries.I suppose this has not been fixed with the newer versions.
Is there anything else I can try? Has this accured before?As always, big thanks in advance!
- This reply was modified 2 years, 9 months ago by emilconsor.
February 8, 2022 at 12:06 pm #1339577Hi,
Thank you for the update.
Two parameters are accepted in the posts_orderby filter, the $orderby and the $query parameters. Have you tried checking the value of the $query parameter? The masonry elements should have a slight difference in their query, so maybe you can use that difference in combination with the is_page function to create a logic in the filter.
// https://developer.wordpress.org/reference/hooks/posts_orderby/
Best regards,
IsmaelFebruary 9, 2022 at 4:34 pm #1339836Hey Ismael,
thanks for the reply.
I’d rather like to debug the infinite reload problem, so when editing the page in the future wont always require make sure the masonry works.
Would you be able to assist me on this topic?Is there a better way to prevent infinite loading than the method mentioned above?
Thanks!
February 10, 2022 at 9:09 am #1339920Hi,
https://kriesi.at/support/topic/masonry-grid-shows-entries-more-than-once/
In the thread above, you mentioned that when using the load more button, there is an infinite loop and duplicated items when sorting is set to random. This issue is not occurring on our installation using the latest version of the theme, 4.8.9.1. We don’t have any masonry filters or custom modifications in this installation. Please temporarily disable all custom modifications and filters for the masonry element, then test the page again. Make sure that the site is updated to version 4.8.9.1.
Do you have a staging version of the site with a fresh copy of Enfold?
Best regards,
IsmaelFebruary 10, 2022 at 11:06 am #1339939To understand your request:
You have a masonry from a specific category ( / taxonomy ) and want to paginate ( or have infinite scroll ) this – and randomize the entries.
You want no duplicates on that.
Now the problem is that you got two different Masonries on the same page and want to influence the orderby specifically to only one of them?February 10, 2022 at 11:36 am #1339948@Guenni007
Not quite. I DO want two seperate masonries.The “Leistungen” Masonry is a Masonry Gallery,
The “Referenzen” Masonry is a Standard Masonry.For the “Leistungen” Masonry I want to rearrange them like it’s supposed to via drag and drop.
“Referenzen” should show random entries.We first had the problem whenever I sort the “Referenzen” by random order, I can forever click the “Load More” Button, it keeps picking 8 random portfolio entries. This creates an infinite loop and duplicate entries. When I sort it by anything else than “random”, the code I posted above works and creates a random sort order with every new user session even though I have f. e. “sort by name” selected in backend.
This however causes the “Leistungen” Masonry to be static and not reorderable. This is my main problem.
@Ismael
We don’t use any custom orderby / masonry filters. This is the only code that works with masonry:// add category tag to masonry grid add_filter( 'avf_masonry_loop_prepare', 'avf_masonry_loop_prepare_mod_cat', 10, 2 ); function avf_masonry_loop_prepare_mod_cat( $key, $entries ) { $categories = get_the_terms($key['ID'], 'portfolio_entries'); //var_dump($categories); $separator = ' '; $output = ' <div class="masonry-cat">'; if ( ! empty( $categories ) ) { foreach( $categories as $category ) { //$output .= '<span alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</span>' . $separator; $output .= '<span>' . esc_html( $category->name ) . '</span>' . $separator; } } $output .= '</div>'; $key['text_before'] .= trim( $output, $separator ); return $key; } //exclude current portfolio entry add_filter('avia_masonry_entries_query','avia_exclude_current_masonry_item',10, 2); function avia_exclude_current_masonry_item($query, $params) { global $wp_query; $postid = $wp_query->post->ID; $query['post__not_in'] = array($postid); return $query; } function avia_year_func( $atts ){ return date("Y"); } add_shortcode( 'year', 'avia_year_func' );
I hope this helps. We use the current theme version too.
Sorry for the wall of text and I highly appreciate the time of yours!
Greetings
February 15, 2022 at 10:41 am #1340668Hello again,
we’re you able to find out anything regarding the problem.
Do you need any more information?Best regards,
Gerry ZellerFebruary 15, 2022 at 1:53 pm #1340701 -
AuthorPosts
- You must be logged in to reply to this topic.