Leave a Reply

2 comments

  1. This line is wrong:

    'meta_key' => 'adminscore' + 'user_like' + '_count-views_all' + 'comment_count',
    

    'meta_key' only accepts string value.

    What you need is an additional meta key, e.g. “totalscore” that holds the total value of the scores you have for all the meta values. You can manually run a php function that calculates and store the totalscore value from time to time or use wp_schedule_event to run the function on a set interval.

    You can then write the $args as such:

    $args = array(
                'meta_key' => 'totalscore',
                'numberposts' => $number_posts,
                'post_status' => $post_status,
                'post_type' => $custom_post_type,
                'orderby' => 'meta_value_num'
    );
    
  2. The only thing you can do here is to use the posts_orderby filter

    To make sure you don’t modify any other queries, use the add_filter call just before retrieving the posts & a remove_filter call either in the hooked function itself or just after you have the posts.