I use the following ACF query to generate a list, works perfectly.
Now, however, I want to order my list by standard WP “post title” instead of ACF custom field “datum”
How can I do that ?
// args
$args = array(
'posts_per_page' => 999,
'post_type' => 'lezing',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => 'datum',
'meta_query' => array(
array(
'key' => 'jaar',
'value' => '2019',
),
)
);
// query
$the_query = new WP_Query( $args );
I use the following ACF query to generate a list, works perfectly.
Now, however, I want to order my list by standard WP “post title” instead of ACF custom field “datum”
How can I do that ?
// args
$args = array(
'posts_per_page' => 999,
'post_type' => 'lezing',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => 'datum',
'meta_query' => array(
array(
'key' => 'jaar',
'value' => '2019',
),
)
);
// query
$the_query = new WP_Query( $args );
Share
Improve this question
edited Feb 10, 2019 at 16:08
Alexander Holsgrove
1,9091 gold badge15 silver badges25 bronze badges
asked Feb 8, 2019 at 10:50
Peter DieperinkPeter Dieperink
11
2
|
2 Answers
Reset to default 1That query has nothing to do with ACF. It's a regular post query using WordPress' standard query class. As such you can refer to the documentation for the options for ordering your query.
To sort by post title you just need to set orderby
to title
:
<?php
$args = array(
'posts_per_page' => 999,
'post_type' => 'lezing',
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'jaar',
'value' => '2019',
),
),
);
$the_query = new WP_Query( $args );
Also note that the quote marks in your original question are incorrect. You need to use non-fancy quotes like '
. This can be an issue if you're copying code from incorrectly formatted blog/forum posts.
Your query will order using the meta term. To order by the post title, you just need to change the orderby
to title
.
Take a look at the documentation for what the parameters mean: https://developer.wordpress/reference/classes/wp_query/#order-orderby-parameters
‘
) in PHP. :) – fuxia ♦ Commented Feb 8, 2019 at 10:52