I'm banging my head to the wall all day trying to figure this out.
I have two meta keys a1 and a2 with numbers inside.
I'm trying to show posts that are a2 > a1.
In a nutshell, here's what I'm trying to accomplish:
$posts = get_posts(array(
'post_type' => 'post',
'meta_query' => array(
//return both meta keys
array(
'key' => 'a1',
),
array(
'key' => 'a2',
),
//only show posts that a2 meta_value is greater than a1 meta_value
'a2' > 'a1'
),
));
I know it should be possible to do this somehow.
I'm not the only one in the world trying to compare whether one post's meta_key value is greater than other...
Desperately need help or any kind of solution.
get_posts
instead ofWP_Query
,suppress_filters
is enabled, so the query cannot be accessed by caching plugins, ensuring the result can never be cached for performance.a2 > a1
as meta, or a taxonomy? Then you would only need to query that. It would be faster and save you needing to filter the results with PHP.update_post_ meta
to update the results right before querying my array? So that it won't lag.