Support

Account

Home Forums General Issues Trouble with acf/fields/post_object/query Filter Reply To: Trouble with acf/fields/post_object/query Filter

  • post__not_in should be an array, so that’s the first suggested change

    
    add_filter( 'acf/fields/post_object/query/name=my_field', [ $this, 'my_filter' ] );
    
    public function my_filter( $args, $field, $post_id ) {
    
    $field; // Undefined
    $post_id; // Undefined
    
    if(isset($post_id)) {
    $args['post__not_in'] = array([$post_id]);
    }
    
    return $args;
    }
    

    If this field is a sub field of a repeater or flex field you also need to use the field key for adding the filter.