Support

Account

Home Forums General Issues Hide values that have been selected in other post Reply To: Hide values that have been selected in other post

  • Hi @hube2 i already fix the error i mentioned above and your code work like a charm. Thank you so much for your amazing help your such a big help to this community. I might need more help in the future because mostly e use ACF on our website.

    Once again thank you so much.

    Here the final code

    `add_filter(‘acf/fields/relationship/query/name=related_tracks_certificate’, ‘remove_already_selected’, 10, 3);
    function remove_already_selected($args, $field, $post_id) {
    $query = new WP_Query(array(
    ‘post_type’ => ‘Tracks’, // my assumption
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1
    ));
    $selected = array();
    if (count($query->posts)) {
    foreach ($query->posts as $post) {
    $tracks = get_field(‘related_tracks_certificate’, $post->ID, false);
    if (!empty($tracks)) {
    foreach ($tracks as $track) {
    $track = intval($track);
    if ($track && !in_array($track, $selected)) {
    $selected[] = $track;
    }
    } // end foreach track
    } // end if tracks
    } // end foreach post
    } // end if posts
    if (!empty($selected)) {
    $args[‘post__not_in’] = $selected;
    }
    return $args;
    } // end function