Home Forums Backend Issues (wp-admin) relationship field search not working once filtered


relationship field search not working once filtered

  • I followed the instructions here to limit the number of posts called to 200. That works perfectly but it breaks the search.

  • could you post your query?

    also, the result which is indicate by your search being termed broken will help; for instance, do you receive any on screen errors?

    is this a development environment or a live environment, do you have wp_debug turned on?

    function tdr_carousel_query( $args, $field, $post )
        $args = array(
            'posts_per_page' => 200
        return $args;
    add_filter('acf/fields/relationship/query', 'tdr_carousel_query', 10, 3);

    no on screen errors. just when you start typing in the search box nothing happens. When I remove the above code it works just fine.

    Production and local

  • two things to try:

    1. firstly, for fun, comment out the $args = array('ppp'=>200); and see if you can just go through the filter with no changes. if not, find the errors, they are either in your javascript console or hiding in your error log (in local do you have wp_debug set to true?)
    2. next, and this may be what you try first if you are querying a particular field, try to be more specific by filtering only the field that you need to filter like this: acf/fields/relationship/result/name={$field_name}

    if you have multiple fields to query against, i wonder if you can dogpile them:

    add_filter('acf/fields/relationship/name=title', 'tdr_carousel_query', 10, 3);
    add_filter('acf/fields/relationship/name=keywords', 'tdr_carousel_query', 10, 3);
    add_filter('acf/fields/relationship/name=description', 'tdr_carousel_query', 10, 3);
  • btw, what version of php are you running? not too long ago, objects weren’t passed by reference…so we could be up against that if you are back on php4.

  • Hi @thesrpr

    If you reduce 200 down to 50, does this fix the issue? It is possible that your server can’t handle querying 200 posts at once.


  • @elliot that the weird part. If I remove it then the search works. There are 6k posts on this site. Search handles them just fine without the above function.

  • Hi @thesrpr

    Can you please read over my previous comment.


  • @elliot I did. Whether I use 50 or 200 doesn’t matter. If I leave the function out (which means it is querying six thousand posts) it works just fine but anything I do to try to reduce that numbers breaks it

  • php version?

    also, can you let me see the site to i can check for any javascript errors?

  • it is local. 5.4. There are no js errors

  • Hi @thesrpr

    I just noticed that your code is completely overriding the $args.
    This is why the WP_Query is breaking. Please modify the $args, not override them.

    You can do this like so:

    $args['posts_per_page'] = 200;
    return $args;
Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘relationship field search not working once filtered’ is closed to new replies.