Home › Forums › ACF PRO › Modify acf relationship search query › Reply To: Modify acf relationship search query
In order to change this you need to add a pre_get_posts filter that will run for the query.
Here is one solution for modifying the search https://wordpress.stackexchange.com/questions/99849/search-that-will-look-in-custom-field-post-title-and-post-content
The best way to add the filter would be something like this
add_filter('acf/fields/post_object_query/name=your_field_name', 'add_my_pre_get_posts_filter', 20, 3);
function add_my_pre_get_posts_filter($args, $field, $post_id) {
// this will cause the pre_get_posts filter to be added only for this query
// add filters that will modify the queries here
}
// this is an example of one filters used to make the needed changes
function some_function_name($args) {
// remove this filter so it will not be run on subsequent queries
// it is called with the same arguments you used to add this filter
remove_filter('the_hook_for_this_filter', 'some_function_name');
// the rest of the filter here
}
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.