Support

Account

Home Forums General Issues Generating ACF Field

Helping

Generating ACF Field

  • Hello! I am using ACF Pro and I want my fields to generate automatically when my custom plugin is activated, so I did like this:
    add_action( 'plugins_loaded', array( $this, 'generate_acf_fields' ) );

    public function generate_acf_fields() {
    		if( function_exists('acf_add_local_field_group') ):
    
    	acf_add_local_field_group(array(
    		'key' => 'group_60c28c944a319',
    		'title' => 'Team',
    		'fields' => array(
    			array(
    				'key' => 'field_60c28ca06cf2a',
    				'label' => 'Position',
    				'name' => 'position',
    				'type' => 'text',
    				'instructions' => '',
    				'required' => 0,
    				'conditional_logic' => 0,
    				'wrapper' => array(
    					'width' => '',
    					'class' => '',
    					'id' => '',
    				),
    				'default_value' => '',
    				'placeholder' => '',
    				'prepend' => '',
    				'append' => '',
    				'maxlength' => '',
    			),
    		),
    		'location' => array(
    			array(
    				array(
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'team',
    				),
    			),
    		),
    		'menu_order' => 0,
    		'position' => 'normal',
    		'style' => 'default',
    		'label_placement' => 'top',
    		'instruction_placement' => 'label',
    		'hide_on_screen' => '',
    		'active' => true,
    		'description' => '',
    	));
    
    endif;
    
    	}

    But it is not generating at all, what is the reason of that?

  • Try changing your action to ‘acf/init’ instead of ‘plugins_loaded’.

    ACF might not be ready to accept registration at plugins_loaded.

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

You must be logged in to reply to this topic.