Support

Account

Home Forums General Issues Remove current post/page from relationship field Reply To: Remove current post/page from relationship field

  • Working version of the code from @roflman79.

    /**
     * Exclude current post/page from relationship field results
     */
    
    // 1. Add the name=[NAME_OF_RELATIONSHIP_FIELD].
    add_filter('acf/fields/relationship/query/name=[NAME_OF_REALTIONSHIP_FIELD]', 'exclude_id', 10, 3);
    
    // 2. Add the $field and $post arguments.
    function exclude_id ( $args, $field, $post ) {
    
        //3. $post argument passed in from the query hook is the $post->ID.
        $args['post__not_in'] = array( $post );
        
        return $args;
    }