Answer the question
In order to leave comments, you need to log in
How to sort a selection (WP_Query) by a custom field after processing its value?
The bottom line is that in an arbitrary field I store a serialized array with data about the rating of the record, a simple array of the type:
array(
user_id_1 => number from 1 to 5,
user_id_2 => number from 1 to 5,
)
When the record is displayed, all this is considered and shown the average rating number is from 1 to 5.
The documentation has an example for sorting by a custom field, however, I need to sort not by the value of the field, but by its processed value. Is there something similar in WP?
Answer the question
In order to leave comments, you need to log in
If you need to perform such calculations, then you have architecturally incorrectly implemented. Such data should not be stored in postmeta, but in a separate table. Structure, roughly (let's call the table post_ratings):
id | post_id | user_id | rating
-------------------------------------
1 | 189 | 34 | 4
well, make a variable, count in it, and put a variable in place of the value.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question