I’m attempting to order the posts in a relationship field by date, newest to oldest, instead of the default alphabetical order:
function my_relationship_query( $args, $field, $post_id ) {
$args = array(
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish'
);
return $args;
}
add_filter('acf/fields/relationship/query', 'my_relationship_query', 10, 3);
This works as intended, but breaks the search functionality. Is there any way to achieve this without breaking the search function?
Thanks,
Dan
Sorry, answering my own question with an (obvious) answer. In case anyone else is interested:
function my_relationship_query( $args, $field, $post_id ) {
$args['orderby'] = 'date';
$args['order'] = 'DESC';
$args['post_status'] = 'publish';
return $args;
}
add_filter('acf/fields/relationship/query', 'my_relationship_query', 10, 3);