Home › Forums › Bug Reports › Page Link and Post Object Field Select2 Search Not Working › Reply To: Page Link and Post Object Field Select2 Search Not Working
I think I see the issue.
One line 1558 of api/api-helpers.php it is sorting the results using
'orderby' => 'menu_order title',
'order' => 'ASC',
For some reason, even though posts_per_page is set to 20, this was not respecting the ‘s’ query arg and returning 20 posts ordered alphabetically. The solution I found was to add a filter on ‘acf/fields/post_object/query’ and set the ‘orderby’ arg to null. This will override the default ‘menu_order title’ argument, and worked for me.
function acf_post_object_custom_query( $args, $field, $post_id )
{
$args['orderby'] = null;
return $args;
}
add_filter( 'acf/fields/post_object/query', 'acf_post_object_custom_query', 10, 3 );
These were my results searching for ‘traffic’.
Before:
After:
If there is a better solution, please post it.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.