Reputation: 538
I have a WordPress custom loop which looks like this:
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'meta_key' => 'publication_type',
'meta_value' => 'uma',
);
This shows 6 posts with publication_type equal to "uma"
. The publication_type
is a field created with Advanced Custom Fields.
I've also created the field publication_year
which contains 2019, 2018, 2017
,...
How is it possible to order all my posts descending?
The following example doesn't do a thing:
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 6,
'order_by' => 'publication_year',
'order' => 'DESC'
'meta_key' => 'publication_type',
'meta_value' => 'uma',
);
Upvotes: 0
Views: 49
Reputation: 185
$args = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'publication_type',
'value' => 'uma',
),
),
'meta_key' => 'publication_year',
'orderby' => 'meta_value_num',
'order' => 'ASC',
));
Upvotes: 1