Home › Forums › Front-end Issues › Call a group datas from another group field › Reply To: Call a group datas from another group field
Yes, you can do it by using the acf/save_post hook. In this hook, you can check if there’s data in the dummy form or not and then create a new post by using the wp_insert_post() function. It should be something like this:
function my_acf_save_post( $post_id ) {
// Only do this for "task" post type
if( get_post_type($post_id) != 'task' ){
return;
}
// Get the posted value
$company_title = get_field('dummy_company_title_name');
$company_custom_field = get_field('dummy_company_custom_field_name');
// Check if there's posted data
if( !$company_title ){
return;
}
// Build the post data
$the_post = array(
'post_status' => 'publish' ,
'post_title' => $company_title ,
'post_type' => 'company' ,
);
// insert the post
$company_post_id = wp_insert_post( $the_post );
// Update the custom field
// "field_1234567890abc" is the field key of the fields in the company post
update_field('field_1234567890abc', $company_custom_field, $company_post_id);
// Remove the saved custom field value in the task post
// "field_abcdefghijk123" is the field key of "dummy_company_title_name"
// and "field_asdfghjklzx123" is the field
// key of the "dummy_company_title_name" field
update_field('field_asdfghjklzx123', '', $post_id);
update_field('field_abcdefghijk123', '', $post_id);
}
// run after ACF saves the $_POST['acf'] data
add_action('acf/save_post', 'my_acf_save_post', 20);
If you don’t know how to code, I suggest you hire a developer to help you out with it, and I’d recommend looking for one on https://studio.envato.com/, https://www.upwork.com/, or https://codeable.io/.
Hope this helps 🙂
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.