Support

Account

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:
    Searching for traffic before filter

    After:
    Searching for traffic after filter

    If there is a better solution, please post it.