Home › Forums › Backend Issues (wp-admin) › 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.
http://www.advancedcustomfields.com/resources/tutorials/customize-the-relationship-field-list-query/
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:
$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?)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.
Thanks
E
@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.
@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?
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;
The topic ‘relationship field search not working once filtered’ is closed to new replies.
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.