Hi,
I’ve a custom post type called “Book”, for which I link custom posts type called “Author” with ACF relationship field.
I would like to order the book posts by their linked author name (the title of the custom post).
What’s the better way to do that?
Hi @cecilehabran
Thank you for the question.
You can achieve this by hooking into the acf/fields/relationship/query filter. You can modify the $args array as follows:
<?php
function my_relationship_query( $args, $field, $post )
{
// increase the posts per page
$args['posts_per_page'] = 25;
$args['orderby'] = 'title';
return $args;
}
// filter for a specific field based on it's name
add_filter('acf/fields/relationship/query/name=my_select', 'my_relationship_query', 10, 3);
?>
You can have a look at the following resource page