Home Forums Front-end Issues Wp_query with relationship to another custom post type Reply To: Wp_query with relationship to another custom post type

  • 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 – – 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,