Support

Account

Home Forums General Issues Problem using function acf_add_local_field

Solved

Problem using function acf_add_local_field

  • I am using this code to create a field in an existing group:

    
    function myfunct()
    {
    acf_add_local_field(array(
                            'key' => 'field_test_field',
                            'label' => 'Test Field',
                            'name' => 'test_field',
                            'type' => 'text',
                            'parent' => 'field_5c2f8603966b9'
                        ));
    }
    
    add_action( 'acf/init','myfunct');
    

    It creates a field, but when editing a post, the fields that were created earlier are not shown. Only the field created by this function

  • What type of field are you trying to add a sub field to?

  • Repeater

  • I don’t know what I was thinking when I first answered this question. Looking back at the OP now I don’t see any reason this should not be working.

    How are the original fields added?

  • I solved the problem.

    Fields were added through the WP interface.
    Later there was a need to add fields programmatically.
    They were added, but those that were previously not displayed.

    How I solved the problem:

    Through tools I generated PHP code.
    Copied the array of fields from there and added it to my code – it worked

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.