Skip to content

Exported PHP doesn't register post_meta #384

@jhmonroe

Description

@jhmonroe

I set up a CPT and two custom fields.
I export the setup as PHP to add directly to the functions.php of a theme.
When trying to use the fields with block bindings it says acf/field is not registered.
Therefore the standalone PHP is not fully working for all the things you might want to use it for in a FSE block theme.

Workaround (from Claude) was to add the following code to the functions that registers those two fields as core/post-meta.

Added benefit: they automatically show up in Block Bindings Attributes menu

would be great if the SCF plugin exported the complete PHP!

add_action( 'init', function() {
    register_post_meta( 'bio-scf', 'bioscf', array(
        'single'       => true,
        'type'         => 'string',
        'show_in_rest' => true,
    ));

    register_post_meta( 'bio-scf', 'linkscf', array(
        'single'       => true,
        'type'         => 'string',
        'show_in_rest' => true,
    ));
});

Here's the PHP SCF exported:

add_action( 'acf/include_fields', function() {
	if ( ! function_exists( 'acf_add_local_field_group' ) ) {
		return;
	}

	acf_add_local_field_group( array(
	'key' => 'group_69aef45532825',
	'title' => 'BioSCFgroup',
	'fields' => array(
		array(
			'key' => 'field_69aef4553c5a5',
			'label' => 'BioSCF',
			'name' => 'bioscf',
			'aria-label' => '',
			'type' => 'text',
			'instructions' => '',
			'required' => 0,
			'conditional_logic' => 0,
			'wrapper' => array(
				'width' => '',
				'class' => '',
				'id' => '',
			),
			'default_value' => '',
			'maxlength' => '',
			'allow_in_bindings' => 1,
			'placeholder' => '',
			'prepend' => '',
			'append' => '',
		),
		array(
			'key' => 'field_69aef4aad1aa1',
			'label' => 'LinkSCF',
			'name' => 'linkscf',
			'aria-label' => '',
			'type' => 'text',
			'instructions' => '',
			'required' => 0,
			'conditional_logic' => 0,
			'wrapper' => array(
				'width' => '',
				'class' => '',
				'id' => '',
			),
			'default_value' => '',
			'maxlength' => '',
			'allow_in_bindings' => 1,
			'placeholder' => '',
			'prepend' => '',
			'append' => '',
		),
	),
	'location' => array(
		array(
			array(
				'param' => 'post_type',
				'operator' => '==',
				'value' => 'bio-scf',
			),
		),
	),
	'menu_order' => 0,
	'position' => 'normal',
	'style' => 'default',
	'label_placement' => 'top',
	'instruction_placement' => 'label',
	'hide_on_screen' => '',
	'active' => true,
	'description' => '',
	'show_in_rest' => 1,
	'display_title' => '',
) );
} );

add_action( 'init', function() {
	register_post_type( 'bio-scf', array(
	'labels' => array(
		'name' => 'Bios-SCF',
		'singular_name' => 'Bio-SCF',
		'menu_name' => 'Bio-SCF',
		'all_items' => 'All Bio-SCF',
		'edit_item' => 'Edit Bio-SCF',
		'view_item' => 'View Bio-SCF',
		'view_items' => 'View Bio-SCF',
		'add_new_item' => 'Add Bio-SCF',
		'add_new' => 'Add Bio-SCF',
		'new_item' => 'New Bio-SCF',
		'parent_item_colon' => 'Parent Bio-SCF:',
		'search_items' => 'Search Bio-SCF',
		'not_found' => 'No bio-scf found',
		'not_found_in_trash' => 'No bio-scf found in Trash',
		'archives' => 'Bio-SCF Archives',
		'attributes' => 'Bio-SCF Attributes',
		'insert_into_item' => 'Insert into bio-scf',
		'uploaded_to_this_item' => 'Uploaded to this bio-scf',
		'filter_items_list' => 'Filter bio-scf list',
		'filter_by_date' => 'Filter bio-scf by date',
		'items_list_navigation' => 'Bio-SCF list navigation',
		'items_list' => 'Bio-SCF list',
		'item_published' => 'Bio-SCF published.',
		'item_published_privately' => 'Bio-SCF published privately.',
		'item_reverted_to_draft' => 'Bio-SCF reverted to draft.',
		'item_scheduled' => 'Bio-SCF scheduled.',
		'item_updated' => 'Bio-SCF updated.',
		'item_link' => 'Bio-SCF Link',
		'item_link_description' => 'A link to a bio-scf.',
	),
	'public' => true,
	'show_in_rest' => true,
	'menu_icon' => 'dashicons-admin-users',
	'supports' => array(
		0 => 'title',
		1 => 'editor',
		2 => 'thumbnail',
		3 => 'custom-fields',
	),
	'delete_with_user' => false,
) );
} );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions