Support

Account

Home Forums Front-end Issues Hide a specific field frontend Reply To: Hide a specific field frontend

  • Thanks John and Jeff,

    So the $field parameter is actually an array like below:

    array(23) {
      ["ID"]=>
      int(0)
      ["key"]=>
      string(15) "_validate_email"
      ["label"]=>
      string(14) "Validate Email"
      ["name"]=>
      string(20) "acf[_validate_email]"
      ["prefix"]=>
      string(3) "acf"
      ["type"]=>
      string(4) "text"
      ["value"]=>
      string(0) ""
      ["menu_order"]=>
      int(2)
      ["instructions"]=>
      string(0) ""
      ["required"]=>
      int(0)
      ["id"]=>
      string(0) ""
      ["class"]=>
      string(0) ""
      ["conditional_logic"]=>
      int(0)
      ["parent"]=>
      int(0)
      ["wrapper"]=>
      array(4) {
        ["width"]=>
        string(0) ""
        ["class"]=>
        string(0) ""
        ["id"]=>
        string(0) ""
        ["style"]=>
        string(24) "display:none !important;"
      }
      ["_name"]=>
      string(15) "_validate_email"
      ["_prepare"]=>
      int(1)
      ["_valid"]=>
      int(1)
      ["default_value"]=>
      string(0) ""
      ["maxlength"]=>
      string(0) ""
      ["placeholder"]=>
      string(0) ""
      ["prepend"]=>
      string(0) ""
      ["append"]=>
      string(0) ""
    }

    I have been able to do some awesome thing :

    function viz_acf_prepare_field($field){
    
    	$userid = get_current_user_id();
    	$user = new Viz_Author($userid);
    
    	if ( ! is_admin() ) : 
    		if ( $field['_name'] == 'client' || $field['_name'] == 'template'  ) {
    			return false;
    		}	 
    		if ( $field['_name'] == 'project_template' ) {
    			$field['disabled'] = 1;
    			$field['wrapper']['class'] = 'viz_hidden';
    			$field['value'] = $user->template;
    		}
    	endif; 
    	return $field;
    }
    
    add_filter('acf/prepare_field', 'viz_acf_prepare_field');

    In the above code, client and template don’t display at the front-end form, and project_template is disabled with a selected value and custom class.

    Thank you all