Support

Account

Home Forums General Issues acf does not create fields with code

Helping

acf does not create fields with code

  • This is the code i exported from the ACF when i tried to create a field via admin panel :

    function af_barbershop_address_field() {
    	if(function_exists("register_field_group"))
    	{
    		register_field_group(array (
    			'id' => 'acf_address',
    			'title' => 'Address',
    			'fields' => array (
    				array (
    					'key' => 'field_address',
    					'label' => 'address',
    					'name' => 'address',
    					'type' => 'textarea',
    					'required' => 1,
    					'default_value' => '',
    					'placeholder' => 'type the address',
    					'maxlength' => '',
    					'rows' => '',
    					'formatting' => 'br',
    				),
    			),
    			'location' => array (
    				array (
    					array (
    						'param' => 'post_type',
    						'operator' => '==',
    						'value' => 'barbershop',
    						'order_no' => 0,
    						'group_no' => 0,
    					),
    				),
    			),
    			'options' => array (
    				'position' => 'normal',
    				'layout' => 'no_box',
    				'hide_on_screen' => array (
    				),
    			),
    			'menu_order' => 0,
    		));
    	}
    }
    
    add_action( 'acf/init', 'af_barbershop_address_field' );

    I also tried to include the acf.php file into my functions.php file :

    $acf_url = WP_PLUGIN_DIR . '/advanced-custom-fields/acf.php';
    include_once( $acf_url );

    All codes are in my functions file. After exporting the code, i deleted the field that created via panel and tried to create the exact same field with code, but it’s not working. What is the problem ? I’ve been dealing with this problem since last week.

  • What version of ACF are you using? I have version 5 but I get ‘acf_add_local_field_group’ instead of the register one.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘acf does not create fields with code’ is closed to new replies.