Home Forums General Issues Relationship no preload, only load on search


Relationship no preload, only load on search

  • Hi,

    I recently started using Relationship field in my project. Its a basic usage: find and add post by title. But what I notice is that this field in backend post editing page takes a long time to load up and when its not the only field loading (i.e. using Post Object fields too), those requests are added to queue. I would like to make that Relationship field would only load results when searched.

    There is this acf/fields/relationship/query filter, but I am not able to think how to use it. My one idea was to check if search argument is empty and if so, simply cancel the query. But how?

    Any help would be appreciated.

  • You would need to alter the query to something that you know will return no results. Query for a meta value that does not exist or something like that. But this will not really improve much. The AJAX request would still be run, the query would still be performed and results (empty) still returned from the request. These things will still consume time.

  • Yeah, this actually was a good idea.

    That’s the code I used and even though it still searches, but the search itself is extremely quick.

    if(!isset($args['s'])) {
    	$args['posts_per_page'] = 1;
        $args['post_type'] = 'asdkjahdiuy';
    return $args;
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.