Home Forums General Issues Exporting Fields with Widget Locations


Exporting Fields with Widget Locations

  • Can anyone tell me if it is possible to create an ACF field group with a “widget” location type? I’m aiming to bundle both the widget code, and the associated ACF fields in the same file if possible.

    So far, I haven’t found a way to make the fields appear on the widget UI once exported. Any clues? Do I need to register the field group with a particular hook to get it to work?

  • The widget should have the same slug (name) on both your dev site and in your new plugin.

    Here is some test generated code I exported.

    if( function_exists('register_field_group') ):
    register_field_group(array (
    	'key' => 'group_5421d12d3b08c',
    	'title' => 'User Registration',
    	'fields' => array (
    		array (
    			'key' => 'field_5421d133e4826',
    			'label' => 'File Upload',
    			'name' => 'file_upload',
    			'prefix' => '',
    			'type' => 'file',
    			'instructions' => 'Upload a file',
    			'required' => 1,
    			'conditional_logic' => 0,
    			'return_format' => 'array',
    			'library' => 'uploadedTo',
    	'location' => array (
    		array (
    			array (
    				'param' => 'widget',
    				'operator' => '==',
    				'value' => 'recent-comments',
    	'menu_order' => 0,
    	'position' => 'normal',
    	'style' => 'default',
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'hide_on_screen' => '',

    As you can see, this add a “File Upload” to the “recent-comments” widget. recent-comments is the slug associated with that widget. This location value must match the widget you are trying to target. Make sure you are assigning a slug when you generate the widget. See the codex info on creating widgets for more info.

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

The topic ‘Exporting Fields with Widget Locations’ is closed to new replies.