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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.