Home › Forums › Backend Issues (wp-admin) › Add subfields with php to the current field type “group” › Reply To: Add subfields with php to the current field type “group”
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( ) {
acf_add_local_field(array(
'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.
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.