Unfortunately that didn't work. It's still passing the value '0' to the custom field.
Maybe it's the process that isn't working for what i wanna do. Here's a run-down:
1) CRED Form that creates a Woo Product
goes to another form->
2) CRED Form that creates a Stream (custom post type) and has a field that establishes relationship to Woo Product
3) CRED Save Data should get the post ID of the related Woo Product, then push that value to a custom field of Woo Product named "wc_pay_per_post_product_ids"
For the record, i've replaced the value "wc_pay_per_post_product_ids" in the update_post_meta portion of CRED SAVE DATA with a generic number to see if that worked, and it did. So i'm not sure what the problem is.
Please note that $post_id is the ID of the post that is being created or edited by the form. So it will be the ID of the Stream post.
You will need to use it in toolset_get_related_post to get the product_id.
And, I understood, that you want to update the post_meta of the product, rather than the Stream post, right?
In that case, "update_post_meta" should use the product_id, instead of the Stream post id.
If you still find trouble implementing this, please allow me temporary access to your website to check this further. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
I will need the following details:
- What form is used to create the product, and on what page it is being used?
- What form is used to create the Stream post, and on what page it is being used?
- Where is located your custom code?
- FTP access to be able to recover the website, in case, I was updating the custom code and I crashed the site.
Thank you for the credentials. I confirm they are working to me.
Here what I gathered so far: - What form is used to create the product, and on what page it is being used?
The form is "Create Stream Product" and used in the page "Add New Stream".
- What form is used to create the Stream post, and on what page it is being used?
The form is "Create Stream Page" and is used in the page "Add New Stream – Step 2"
I will still need to know:
- Where is located your custom code? It is not available in Toolset->Settings->Custom code. And I do not have access to the theme editor.
- FTP access to be able to recover the website, in case, I was updating the custom code and I crashed the site.
Thank you for the FTP access. As I will need to understand better the workflow of your process and where I can check the value of the custom field(probably in the database, using a tool, such as phpMyAdmin or Adminer), I wonder if you could test the following code:
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==1386)
{
// $product_id = get_post( get_the_ID() );
$stream_product_id = toolset_get_related_post( $post_id, 'product-stream', 'parent' );
update_post_meta($post_id, 'wc_pay_per_post_product_ids', $stream_product_id, true);
}
}
It would be hard for me to debug the code on your current website. For that reason, I created a test site on our platform, please reproduce a minimal example that can be similar to your case and let me debug it.
You can log in to our test site with the following URL hidden link
The topic ‘[Closed] Passing The ID of Related Post To Another Custom Field’ is closed to new replies.