Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #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.

    #933501

    Hey 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,
    Victoria

    #933679

    Thanks, 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)?

    #933765

    Hi,

    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,
    Nikko

    #933769

    Tried 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?

    #933884

    I 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?

    #934085

    Hi 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,
    Victoria

    #934430

    Thanks, but it doesn’t work. Is this the right code for displaying masonry posts?

    #934844

    Hi,

    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

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