Custom Fields
Re-Envisioned
Support General Remove metabox field with filter

  • Creator
    Topic
  • #15522
    Joseph VanTine
    Participant

    I’m trying to create a filter so we can remove fields from a metabox.

    This is the function that I have created to it. It returns null as aspected, but the field is still there in the metabox.

    Code:

    
        /**
         * filter fields
         */
        public function syb_filter_fields( $fields ) {
    
            foreach ( $fields as $field ) { 
                
                if ( $field['id'] == 'boat-details' ) {
                    
                    foreach ($field['fields'] as $key => $value) {
                        
                        if ( $value["id"] == 'field-id' ) {
    
                            $value = NULL;
                        
                        }  
                    }
                }
            }
     
            return $fields;
    
        }
    
Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #15541
    Anh Tran
    Keymaster

    Hi Joseph,

    You can try unset( $field['fields'][$key] ) instead of setting the $value = null. How did you run the function?

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.