I have written a wp query to list custompost types (motobikes) based on 2 keys. (brand which is variable and type)
The query works and lists my customposts properly, but I would like to order them based on a 3 key value which is the cylinder (‘key => cylindree’)
I did not find a way to order by a specific custom field value that is not in the query.
Here is my query so far :
$args = array(
'post_type' => 'motos',
'posts_per_page'=> -1,
'meta_query' => array(
array(
'key' => 'categorie',
'value' => 'Roadster'
),
array(
'key' => 'marque',
'value' => $meta_value
)
)
);
[…]
Thank you for your help.
Best regards.
You can add a
meta_key
to order by:Try this, it works for me: