[Résolu] A form which allows me to add a product and connect a custom post type
This support ticket is created Il y a 5 années et 4 mois. 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
add_action('cred_save_data', 'cred_custom_callback_fn',10,2);
function cred_custom_callback_fn($post_id, $form_data)
{
$forms = array( 98 );
// if a specific form
if (in_array($form_data['id'], $forms))
{
if (isset($_POST['connect-posts']))
{
$parent_id = $_POST['connect-posts'];
$parent = toolset_connect_posts( 'organization-campaign', $parent_id, $post_id );
// your other callback code continues here
}
}
}
Thanks for writing back and glad you've found the solution.
The code that you shared originally and the new one are both correct and should work.
The only thing that needs to be updated in your old code is the name of the generic field. Since you're using a custom generic field, you don't need to use the method/format of "@organization-campaign.parent" for the field's name.
You can update it to regular text name (e.g. "connect-posts") in the generic field's code and the hook's function and it will work.
There is no direct method for this and you'll need a couple of steps to achieve this in an edit form:
1. First, you'll need the value of the connected parent post in the edit form. You can add a new shortcode for this that first gets the ID of the current post which is being edited (assuming you're using the edit form on the same post which is being edited through the edit form) and then returns its connected parent post's ID:
3. The last step would be to add some script to select the radio button, whose value matches the value of the new hidden generic field. In your edit form's "JS editor" tab, you can include:
Note: For even more personalized assistance around custom code, you can consider hiring a professional from our list of recommended contractors at: https://toolset.com/contractors/
Thanks Waqar,
yeah the thing is that I am not using the edit form on the same post which is being edited through the edit form but on a different page.
add_shortcode( 'showparentpostid', 'showparentpostid_func');
function showparentpostid_func(){
$product_id = get_post( get_the_ID() ); // Get ID of current product
$auction_parent_page_id = toolset_get_related_post( // Get ID of parent auction page
$product_id,
'organization-campaign', //slug of relationship
'parent'
);
return $auction_parent_page_id;
}