Support

Account

Forum Replies Created

  • Thanks! That was very helpful. What I was trying to do was loop through a certain set of post types and dynamically add them as subfields of a group along with a bunch of subfields for each post type.

    You were correct that I should be doing it when the group field is registered, not when it loads.

    Also, all field keys should start with ‘field_’ not ‘sub_field_’. I still could not get the options to save, however, because of another problem.

    Because I was using a foreach loop to create the subfields on each post type, I was using a random number on each pass through the loop, trying to prevent duplicate field keys.

    What I didn’t realize was that this meant the field keys kept changing. Every time I tried to save options, the field key would change, so of course nothing was saving in the database!

    So, to fix it I just had to use the post type in the field keys instead of a random number. That way they would be unique AND permanent. Problem solved!

    Thanks again.

  • Sorry, it’s a lot of code, but thank you for your time. I don’t know the best way to share it, but hopefully this is okay.

    I’m using this filter:

    add_filter('acf/load_field/key=field_604de6ee3ffc6', 'acf_load_post_type_groups');

    to add subfields to a field of type “Group” (because I need them to be dynamic).

    Here is the group field:

    acf_add_local_field_group(array(
    	'key' => 'group_604dda92ef574',
    	'title' => 'Archives',
    	'fields' => array(
    		array(
    			'key' => 'field_604de6ee3ffc6',
    			'label' => 'Archives',
    			'name' => 'archive_options',
    			'aria-label' => '',
    			'type' => 'group',
    			'instructions' => 'Archive pages are lists such as the main blog page, search results, and category and tag pages. Choose layout, appearance, and other options for such pages from the list below for each post type.',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array(
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'layout' => 'block',
    			'acfe_seamless_style' => 0,
    			'acfe_group_modal' => 0,
    			'acfe_group_modal_close' => 0,
    			'acfe_group_modal_button' => '',
    			'acfe_group_modal_size' => 'large',
    			'sub_fields' => '',
    		),
    	),
    	'location' => array(
    		array(
    			array(
    				'param' => 'options_page',
    				'operator' => '==',
    				'value' => 'theme-options',
    			),
    		),
    	),
    	'menu_order' => 10,
    	'position' => 'normal',
    	'style' => 'seamless',
    	'label_placement' => 'top',
    	'instruction_placement' => 'label',
    	'hide_on_screen' => '',
    	'active' => true,
    	'description' => '',
    	'show_in_rest' => 0,
    	'acfe_display_title' => '',
    	'acfe_autosync' => '',
    	'acfe_form' => 0,
    	'acfe_meta' => array(
    		'604dddb8749bf' => array(
    			'acfe_meta_key' => '',
    			'acfe_meta_value' => '',
    		),
    	),
    	'acfe_note' => '',
    ));

    The ‘sub_fields’ => ”, part is getting loaded from a function in functions.php using that filter.

    Here’s the function:

    (ATTACHMENT-1)

    Here’s what I get when I look at the php that is being generated by ACF:

    (ATTACHMENT-2)

    And here’s how it looks on my Theme Options page:

    archive-options-page

    Each post type has the same set of options. Everything else on the options page is saving just fine, but not this stuff.

    My fields are getting generated but nothing is saving. I originally said that it was saving to the database, but it’s not now.

    The database looks kind of weird, too:

    acf-database-rows

    Any idea what I’m doing wrong? I assume there’s something seriously wrong with that function even though the fields are getting generated.

  • Yes, I know there is nothing built into ACF for Quick Edit, which is why I already built it myself. So, that doesn’t answer my question. Can you read the question again, please?

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