Home › Forums › Front-end Issues › Call a group datas from another group field
Hello,
Please let me know if it’s posible to call a group data from another group field.
so, i will try to explain.
I have 2 group.
1: Company
field: company name, contact details, address
2: Products
field: name products, type products.
Then on the post, i want to add a task work. when i add a task i want to asign to one company.
But if i will add another task to the same company, i want to have one fied where i can select the company that i have already added.
Please let mw know if you understend my issue ?
Many regards.
In this case, I suggest you use a custom post type for the company. That way, you can create the company first and then use the post object field to select the company you’ve created.
Later, if you want to select the same company, then you can just select it from the post object field.
You can also easily create the custom post type by using a third party plugin like Custom Post Type UI.
I hope this helps π
Hello,
That’s means i wil have 2 custom type.
1: Companie
2: Task’s
and will be dificult to complet the company profile for a new company on the same page.
I will try to do it. I just install the type plugin and i will see how i can do it.
Many thank’s for help.
ps: on the PRO version it’s not posible ?
I’m afraid the PRO version doesn’t have the feature you want. If you want, you can create dummy custom fields to provide the form for a new company profile, and then use the acf/save_post hook to save the new company profile to the company custom post type. But I’m afraid you need advanced code to do it.
Hope this helps π
Hello,
I see this featured “dummy custom” and i belive it’s OK for my request.
It’s dificult for me to code it on the source.
If you help me how much cost it one work hour ?!
Hello,
So, i have instal Wp types plugin.
I have created 3 post type:
1: Company
2: Products
3: Task.
When i add a new task, i can call the comapany and the products from the post type.
Now, the big problem it’s: If i want to add a new company on the same page, i must complet another fields.
After i complet the fields it’s posible to migrate the field on the company type ?
Many regards.
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 π
You must be logged in to reply to this topic.
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!
βEver wondered when and why ACF uses JSON instead of the database? Check out our summary of the most recent session of ACF Chat Friday for the answer, and make sure to register for the next session.
— Advanced Custom Fields (@wp_acf) February 23, 2023
π https://t.co/3UtvQbDwNmhttps://t.co/wfFEVcXVKc
© 2023 Advanced Custom Fields.
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.