Hi i’d like to order by multiple meta_keys
want to make it order using these keys
adminscore + user_like + _count-views_all + comment_count
combine these keys how should i array order it??
i try this but not work..
$args = array(
'meta_key' => 'adminscore' + 'user_like' + '_count-views_all' + 'comment_count',
'numberposts' => $number_posts,
'post_status' => $post_status,
'post_type' => $custom_post_type,
'orderby' => 'meta_value_num'
);
Thanks for check my question, hope someone has answer for it.
This line is wrong:
'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:
The only thing you can do here is to use the
posts_orderby
filterTo make sure you don’t modify any other queries, use the
add_filter
call just before retrieving the posts & aremove_filter
call either in the hooked function itself or just after you have the posts.