Hi, I’m trying to include in the WordPress search the repeater field, essentially I have this situation:
There is a cpt called “service” which can have multiple “doctor” (cpt), each “doctor” is associated through the repeater field “medici”, infact if I inspect the postmeta table I have this:
as you can see I have a list of ids in the “medici” meta_key.
So suppose that I have this situation: a “service” with post_title “lorem ipsum”, to this “service” are linked a list of “doctor” eg: (paolini, rossi, mario). I would like that if I search for “paolini”, I will get the “lorem ipsum” post.
So I wrote this code:
`
function add_acf_to_search( $query ) {
if( $query->is_search ) {
$query->set( ‘meta_query’, array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘medici’,
‘value’ => $query->query_vars[‘s’],
‘compare’ => ‘LIKE’
)
));
}
}
add_action( ‘pre_get_posts’, ‘add_acf_to_search’ );
`
the problem’s that if I search for a “doctor” linked to a “service” I doesn’t get any result.
Any idea?
PS: I don’t want use any plugin.
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.