[Resuelto] Automatically set post parent in post form from URL parameter
Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.
Problem:
Automatically set post parent with Toolset CRED form using new post relationship
Solution:
You can use new post relationship API function 'toolset_connect_posts' in order to connect two posts in relationship of parent and child in conjunction with the use of cred_save_data hook.
For example:
add_action('cred_save_data','func_custom_post_title',15,2);
function func_custom_post_title($post_id,$form_data) {
if ($form_data['id']==243) {
toolset_connect_posts('boat-safety-check',$_POST['@boat-safety-check_parent'], $post_id);
}
}
This support ticket is created hace 6 años, 6 meses. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.
Which sounds to me like it should do what I want. I've added that code, and the parent is correctly set in the CRED form, but when I submit the fom, there is no relationship saved?!?
I used following code to set your current post ID value for parent select dropdown:
[cred_field field='@boat-safety-check.parent' select_text='--- not set ---' value="[wpv-post-id]" use_select2="never" class='form-control' output='bootstrap']
Well - I would like to know here - have you migrated from the legacy post relationship with new many to many post relationship OR you just build everything with Toolset Beta plugins?
Ok - the thing was that the API support for new relationship was not released yet but as it was a simple change, only 2 files needed to make this work. I've updated those required files to your types and CRED plugins.
However - we are going to release new version for all Toolset plugins by next week, its currently undergoing QA.
I've added following code to your current theme's functions.php file:
add_action('cred_save_data','func_custom_post_title',15,2);
function func_custom_post_title($post_id,$form_data) {
if ($form_data['id']==243) {
toolset_connect_posts('boat-safety-check',$_POST['@boat-safety-check_parent'], $post_id);
}
}
Now, I can see that once you add the new record - in backend its displayed as connected to selected boat. Could you please confirm.
OK, great! thanks heaps- appears to be working! OK, so do I need to remove that code once it's updated I assume? Will I get notified of the update in the WP dashboard or do I need to come back here to get the latest versions?
Glad to know that its working fine now for you as well.
do I need to remove that code once it's updated I assume?
==> No - you need to keep the code I've added in your functions.php file.
Will I get notified of the update in the WP dashboard or do I need to come back here to get the latest versions?
==> Yes - once we release new version - you will see the notice on your plugins page to update plugins to latest version. However - please keep eye on our blog to have latest updates.
=> https://toolset.com/blog/
OK, so if I add another child post type i'm gonna have to add more if statements? That seems problematic- this all seems like a pretty basic function that should just work from the start?
We are about to release the new version and your comments are valuable for us. As your original issue is resolved, May I kindly ask you to open a new ticket with your each new question. This will help other users searching on the forum and help us to write correct resolve ticket summery.
Thank you for understanding. Glad to help. Have a nice day!