Not working… I have tried many combinations and nothing
Thanks @keithlock, we are near, but the last step is not working and I cannot figure it out. For testing I have simple query
$args = array(
'post_type' => 'branch_clinic',
'meta_key' => 'hospital', // relationship field
'meta_value' => '536', // ID of hospital
'meta_compare' => '=',
);
But it is not working. If I get ID from hospital in regular query, I get right ID – 536
<?php the_field('hospital'); ?>
If I fill with any other fields (branch name) it works. It looks like, that Relationship field cannot be as meta_key… Or do you know, what is going on?
———————-
For explanation, chech this page – http://tuaestetica.pavlovec.net – it is in Czech language, you can switch to English, but it is without data… If you click on “Kliniky” you will see all Hospitals. If you will click on hospital, you will see the detail and all branches at the bottom. In the sidebar, you can specify, which branches you looking for – select location and/or procedure. Here you will see all branches. And there should be those RECOMMENDED branches first and than others.
———————-
Thanks a lot for your helping,
Jakub
Thanks @keithlock for the code, but it doesn’t work.
If I understand the code right – I think there is a mistake in a part “this *should* work (untested)”. The relationship field is on “Branch side”. In administration of branch – there I choose relationship to hospital.
Am I wrong?
Thanks for your helping
thanks @keithlock, but I can’t imagine how should the code looks like. Can you write an example?
Thanks,
Jakub
Hello @keithlock, thanks for your help. But I dont have problem with “True/False” field, I need link the_query to another post_type with relationship field. Logic of query should be like this, but meta_query doesnt support “post_type”:
<?php
$args = array(
'post_type' => 'branch_clinic',
'posts_per_page' => 10,
'meta_query' => array(
array(
'post_type' => 'hospital',
'key' => 'template-part-clinic-heading__highlight',
'value' => '1',
),
),
);
$the_query = new WP_Query( $args );
?>
“template-part-clinic-heading__highlight” is TRUE/FALSE field in HOSPITAL post type, and this hospital is linked by relationship field to BRANCH CLINIC.
Thanks,
Jakub
Nobody? 🙁
I am an idiot… I found your tutorial:
– https://www.advancedcustomfields.com/resources/querying-relationship-fields/
Solved, sorry for this.
Please delete this post.
Thanks,
Kubajjz
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.