WP_Query - Order results by meta value
-
30-10-2019 - |
Pergunta
I've checked around and haven't seen an answer which works as of yet. I have a WP_Query with the following arguements:
$args = array(
'post_status' => 'publish',
'post_type' => 'listing',
'meta_key' => 'client_feedback_score',
'orderby' => 'client_feedback_score',
'order' => 'DESC'
);
$query = new WP_Query($args);
I want to order the results by the custom post field 'client_feedback_score', lowest to highest. But this doesn't seem to work... can anyone point me in the right direction?
EDIT (SOLVED):
Thanks to Milo's response, here's the working code for ordering by a numerical meta value:
$args = array(
'post_status' => 'publish',
'post_type' => 'listing',
'meta_key' => 'client_feedback_score',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
Nenhuma solução correta
Licenciado em: CC-BY-SA com atribuição
Não afiliado a wordpress.stackexchange