Home Forums Backend Issues (wp-admin) Add subfields with php to the current field type “group”


Add subfields with php to the current field type “group”

  • I really need help or advice from experts. My task is to create a set of text fields in the field type=group (which is created in the admin panel) depending on the value of the post fields.

    I’m actually making a table editor. The two repeating fields will contain the names of the columns and rows. Now I want to make a grid table with text fields. Calculate their % width (to make a view like a table) and add this unique set of text fields for each page.

    But for example, I need to solve the simplest problem – create a subfield for an existing field group. I saw how to add a separate group of fields using PHP. But I want to change the set of fields in an existing (empty in the admin panel) group.

    I would be eternally grateful for your help as it will open the door to many things in the future. Thank you!

  • Hi, adding a subfield to an already existing group is rather simple: you just add a property in the field declaration, telling which is the parent group :
    'parent' => 'group_1'

    See in details here : under “Individual”

  • I’ve figured out that my problem is to get current post_id when add_filter(‘acf/init’, ‘acf_load_table_grid’); call.
    I’m trying to create fields from the current field data of the current post. But it doesn’t save field data. I’ve checked it. So reason is that in this filter impossible to get post_id ($_GET[‘post’]) when fields are saving. Do you have any ideas how to correctly get post_id? Because when fields are saving script “knows” what post in the process, evidently.
    I’m sure it’s possible.

    Let’s imaging that you want to create such function:

    add_filter('acf/init', 'acf_load_table_grid');
    function acf_load_table_grid( ) {
    				'key' => 'field_mypost'.get_the_ID(),
    				'type' => 'text',
    				'name' => 'field_myfield_myfield'.get_the_ID(),
    				'parent' => 'some_parent_field',

    get_the_ID(), $_GET[‘post’] – doesn’t allow to save data in field

    So any suggestions?
    Thanks for your attention! Support rejected me in any help even I have PRO subscription.

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

You must be logged in to reply to this topic.