Home › Forums › General Issues › Relationship query help › Reply To: Relationship query help
Hi @sccr410
Sorry about that, I read your above comment and though you were using a repeater field for each doctor!
Please don’t use a repeater field for this. Continue to use the 2 post types related via a relationship field.
Okay, so to achieve the original question, you will need to perform 2 seperate queries on the DB.
The first query is to find the locations within the radius. There are a few tutorials on stack overflow which talk about SQL radius calculations which I have done once before on a complicated search directory and it did work correctly.
Next, once you have all your locations, you can build up the meta_query args for each doctor.
Taking straight from the docs, to find a doctor which is connected to location 2, you would have:
<?php
$doctors = get_posts(array(
'post_type' => 'doctor',
'meta_query' => array(
array(
'key' => 'location',
'value' => '"' . 2 . '"',
'compare' => 'LIKE'
)
)
));
?>
So to find any doctors working in location2, 3, or 4, you would have:
<?php
$doctors = get_posts(array(
'post_type' => 'doctor',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'location',
'value' => '"' . 2 . '"',
'compare' => 'LIKE'
),
array(
'key' => 'location',
'value' => '"' . 2 . '"',
'compare' => 'LIKE'
),
array(
'key' => 'location',
'value' => '"' . 3 . '"',
'compare' => 'LIKE'
)
)
));
?>
To produce this meta_query args, you can simply loop over the results from DB query #1.
Hope that helps.
Thanks
E
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.