Use _wpsso_meta-> schema_review_rating in meta_query
-
I’m working on a plugin which will retrieve posts on my site by rating (currently stored in _wpsso_meta-> schema_review_rating). Because the schema_review_rating value is nested within the _wpsso_meta meta value, I’m not sure how to compare against the desired value. For example, our ratings are in .5 increments on a .5 to 5 scale. If the property wasn’t nested, I believe the following query would do the trick.
$reviews = get_posts([
'post_type' => 'reviews',
'post_status' => 'publish',
'posts_per_page' => 10,
'order' => 'ASC',
'orderby' => 'title',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'schema_review_rating',
'value' => $rating,
'compare' => '='
),
array(
'key' => 'schema_review_rating',
'value' => $rating . '.5',
'compare' => '='
)
)
]);The goal of the previous query is to retrieve all posts with a rating of 4 or 4.5, and display them ordered by post title. Any suggestions on how to proceed?
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- You must be logged in to reply to this topic.