Support

Account

Home Forums Backend Issues (wp-admin) Relationship field with filter for custom field Reply To: Relationship field with filter for custom field

  • I think I have the same question as the above user. If only I knew what to do next…

    I am using ACF to add a custom checkbox to my personnel posts to I can identify what type of personnel they are (e.g. ‘writer’, ‘graphic_designer’).

    On another type of post, I would like to add a custom relationship field that allows me select only a specific type of personnel when I search. I thought this forum topic was the answer.

    I opened functions.php and put the below-referenced code into that. I thought maybe if I went back to the Custom Fields group/field and try again to configure my field that ‘playwright_query’ would show up in the “filter by Post Type.” No such luck. What’s the next step? Is what I am trying to do even possible?

    ——— CODE ———–
    function playwright_query( $args, $field, $post_id ) {

    // only show children of the current post being edited
    $args[‘meta_query’] = array(
    array(
    ‘key’ => ‘personnel_type’, // name of custom field
    ‘value’ => ‘”playwright”‘,
    ‘compare’ => ‘LIKE’
    )
    )

    // return
    return $args;

    }

    // filter for every field
    add_filter(‘acf/fields/relationship/query’, ‘playwright_query’, 10, 3);
    ———————————–