Support

Account

Home Forums General Issues Querying a relationship field with a custom field filter Reply To: Querying a relationship field with a custom field filter

  • Hi @charlesr

    In that case, you need extra parameters to query the doctors like this:

    $doctors = get_posts(array(
        'post_type' => 'doctor',
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'location', // name of custom field
                'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
                'compare' => 'LIKE'
            ),
            array(
                'key' => 'gender', 
                'value' => 'male', 
                'compare' => 'LIKE'
            )
        )
    ));

    If you want the radio button to act like a filter, please take a look at this page to learn more about filtering posts with ACF: https://www.advancedcustomfields.com/resources/creating-wp-archive-custom-field-filter/

    I hope this helps 🙂