currently at priority 20
i can see this key inside postmeta table in mysql, it should be registered. i tried to access permalink for manual execution, it filled the field then set back to draft then publish again, still doesn’t update the field. it has to be registered, i can see content in it.
the field is added together with all other fields (total 15 fields) in a separate php file. the php file is loaded in the beginning inside functions.php
this is the only field that has update_field. the rest of the fields are user input and get_fields are working find from inside action hook function
under Getting Started, it only says the key must be unique, doesn’t mention it must be started with “field_”. Anyway, i changed the keys to start with “field_”, still same problem
i have the same identification for both key and name. i did tried to differentiate the key and name but didn’t work.
the field does exist, checked the postmeta table in mysql but there’s no value. tried the page template and it does filled the textarea. tried to switch post status to draft then publish, it does not update the textarea field which was populated using the page template
the variable $pcontent does has value hence it’s not empty, this is confirmed.
my guess is the update_field is not working from inside the hook action (btw, it’s not filter). but i can’t think of any reason.
update_field(‘talist’, $pcontent, $post->ID);
this is the code that doesnt run inside the action hook. the ‘talist’ is the field key/name.
the same line is working inside page template
the situation:
i have a custom post type where fields are created using php (not acf gui). one of the fields, a readonly text area, is supposed to be populated after users save draft then click publish.
the actual code:
created a function that do some string generation using while loop. at the last line of the function, update_field the text area. it hooked into draft_to_publish action with priority 10 (tried 5 and 20, same issue)
the problem:
all codes in the function are run without error (this is tested and verified) but the field is not updated.
the test:
we copied all codes inside the function to a page template, link it with that particular content, visit the permalink to execute the code. it runs fine and updated the textarea field
hope that’s more clear on the problem
it’s inside functions.php and not working.
when copied to page template, only the code from inside the function, excluding the action hook lines
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.