Is their anyway we can do the filtering (i.e comparing 3 values) in
wp_query itself?
What you are asking is tricky in pure SQL, though it can be done. WP_Query
cannot handle the logic natively, though. You would have to create one or more filters.
Doing this with the data structure you have right now is not ever going to be especially efficient though. The best answer has already been suggested in a comment– change your data structure so that you are saving rating to a single key such as my_gob_rating
. You can then retrieve your data with a meta_query
. Like this:
$args=array(
'post__not_in' => array(get_the_ID()),
'posts_per_page' => 10, // Number of related posts to display.
'meta_query' = array(
array(
'key' => 'my_gob_rating',
'value' => 10, // whatever the cutoff is between 'ok' and 'good'
'compare' => '>=',
)
),
'ignore_sticky_posts' => true
);
You can change the compare
operator to BETWEEN
to get your “ok” data, and to <
to get your “bad” values, if needed.
Also…
ignore_sticky_posts
(boolean) – ignore sticky posts or not (available
with Version 3.1, replacedcaller_get_posts
parameter). Default value
is 0 – don’t ignore sticky posts. Note: ignore/exclude sticky posts
being included at the beginning of posts returned, but the sticky post
will still be returned in the natural order of that list of posts
returned.