Home › Forums › General Issues › Remove current post/page from relationship field › Reply To: Remove current post/page from relationship field
Hi Elliot, it’s probably my fault, but I am not able to exclude the current post from the field. I have a very strange issue here, here is is my code:
add_filter('acf/fields/relationship/query', 'exclude_id', 10, 3);
function exclude_id ($args) {
$current_id = $_GET['post'];
$args['post__not_in'] = array($current_id);
return $args;
}
This doesn’t work, but if I hardcode the id (e.g. $args[‘post__not_in’] = array( 115 ); ) I obtain the exclusion.
I tried to substitute $_GET with:
$current_id = (int) $_GET['post'];
$current_id = intval($_GET['post']);
global $post;
$current_id = $post->ID;
But I had no luck..
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.