• Resolved wxia0822

    (@wxia0822hotmailcom)


    Hi,

    Is this possible I sort the post order on ratings?

    This is the code I added into functions.php:

    
    // Sort the posts by highest to lowest rating order on home page. 
    function custom_post_order_sort( $query ){
      if ( $query->is_main_query() && is_home() ){
        $query->set( 'orderby', 'meta_value' );
        $query->set( 'meta_key', 'ratings_average' );
        $query->set( 'order' , 'DSC' );
      }
    }
    add_action( 'pre_get_posts' , 'custom_post_order_sort' );

    I guess if you can give me a “meta_key”, it seems like I can achieve it.

    I saw a similar ticket 3 years ago and it says “impossible” at that time. Not sure if I can make it today.

    This is the site: https://thehealthpursuit.com

    Thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter wxia0822

    (@wxia0822hotmailcom)

    I just used another plugin so it is fixed.

    Thanks for the nice free plugin. It is still one of the best although I have this issue.

Viewing 1 replies (of 1 total)
  • The topic ‘Sort the order of post on home page’ is closed to new replies.