-
AuthorPosts
-
March 26, 2018 at 9:45 pm #933204
Hi,
We’d like to sort the blog posts that are showing in Masonry so that the ones with the most comments appear first. I’ve read up on sorting alphabetically, etc. using functions.php (https://kriesi.at/documentation/enfold/change-the-sort-order-of-blog-posts-elements/) but I haven’t seen anything about sorting by popularity. Any suggestions?Thank you.
March 27, 2018 at 9:38 am #933501Hey GWS,
Here is the code you can put in your funtions.php
add_filter('avia_blog_post_query', 'avia_modify_post_grid_query_desc'); function avia_modify_post_grid_query_desc( $query ) { $query['orderby'] = 'comment_count'; $query['order'] = 'DESC'; return $query; }
If you need further assistance please let us know.
Best regards,
VictoriaMarch 27, 2018 at 2:39 pm #933679Thanks, Victoria. I think that may be what is needed, but think the sort is starting with the LEAST popular posts in ascending. What can I add to force it to load the ones with the most comments (descending order)?
March 27, 2018 at 5:22 pm #933765Hi,
The code Victoria gave should have the most comments on top then the least comments will be bottom, if you want it in reverse order you can change DESC with ASC.
Hope it helps :)Best regards,
NikkoMarch 27, 2018 at 5:27 pm #933769Tried that. It doesn’t change the order either way — the masonry blog posts are still displaying by date. Is there anything else we can try?
March 27, 2018 at 9:37 pm #933884I found out that number of comments is not what is needed for ‘popular posts’. Rather the number of views. I think you said in another post that there are plugins for popular posts, but that they probably won’t work with the Avia masonry elements. Is this still the case, or do you know of a plugin to recommend?
March 28, 2018 at 10:17 am #934085Hi GWS,
Try this code:
add_filter('avia_blog_post_query', 'avia_modify_post_grid_query_desc'); function avia_modify_post_grid_query_desc( $query ) { $query['meta_key'] => 'meta_value_num'; $query['orderby'] = 'meta_value_num'; $query['order'] = 'DESC'; return $query; }
If you need further assistance please let us know.
Best regards,
VictoriaMarch 28, 2018 at 6:10 pm #934430Thanks, but it doesn’t work. Is this the right code for displaying masonry posts?
March 29, 2018 at 2:56 pm #934844Hi,
We modified the filter a bit because the previous one is intended to alter the blog posts query. The following filter is for the masonry element.
add_filter('avia_masonry_entries_query', 'avia_masonry_entries_query_mod', 10, 2); function avia_masonry_entries_query_mod($query, $params) { $query['orderby'] = 'comment_count'; $query['order'] = 'DESC'; return $query; }
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.