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.