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 Thank you so much for your response, I appreciate it

    Upon using your code.

    add_filter(‘acf/fields/relationship/query/name=related_tracks’, ‘remove_already_selected’, 10, 3);
    function remove_already_selected($args, $field, $post_id) {
    $query = new WP_Query(array(
    ‘post_type’ => ‘album’, // 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’, $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

    There is error on this line ‘$selected[] = $track;’

    the error is syntax error, unexpected ‘;’

    Sorry im very newbie on coding.