Tell us what you are trying to do?
I wan to make sure the parent CPT "project prompt" taxonomy entries get transferred to child CPT "project submission".
Is there any documentation that you are following?
I followed the steps and created custom code in Toolset following this article:
https://toolset.com/forums/topic/match-child-post-taxonomy-to-parent/#post-1195977
I appended the shortcode to the URL as hidden link
I am using the parent prompt id to link the two posts.
What am I missing?
To provide more context, I have also done the following: 1) Activated the snippet, 2) test run the snippet (it runs without error), 3) the form id used is the id of the "project submission" CPT submit form and 4) parent id is the id of the "project prompt" parent post.
Hello,
Since it is a custom codes problem, please provide a test site with the same problem, also point out the problem page URL and where I can edit your PHP codes, I need to test and debug it in a live website, private message box enabled.
Thanks for the details, I can login your website, please point out:
- problem page URL, where I can test the result in front-end
- where I can edit your PHP codes
Thanks
1. You should be able to enter "project prompt" on prompt creation page: hidden link
2. In the project prompt, you can select parent categories for project, skill and industry.
3. On submitting the form you are directed to review project prompt. There you can click on add project submission button. It will take you to "project submissions" post entry form.
4. On submitting the "project submission", you are directed to "project submission template where I have shortcodes that are showing data from the parent .
5. If your query works, we should we able to see parent categories in the child project submission posts page in WP: hidden link
The code is written in Toolset settings custom code section under the name add_parent_taxonomy (hidden link). The code is currently inactive so you will have to activate again to see the impact. The code has the form id and parent post id hardcoded. So please select the same parent or make the code universal.
Hi,
Thank you for sharing these steps.
Luo is on vacation, so I'll be following up on this ticket.
I'll need to perform some tests on my website with a similar setup and custom code, to investigate this and will update you, as soon as this testing completes.
Thank you for your patience.
regards,
Waqar
Thanks Waqar. Looking forward to hearing from you.
An update on the issue would be appreciated. Thank you.
I apologize for the delay in getting back on this, as I had an unusually busy queue over the weekend.
I'll be able to share my findings in the next few hours. Thank you for your patience.
Thank you for waiting.
I've looked into the custom code snippet named "add_parent_taxonomy" and noticed that it targets the taxonomy named "item" which is not being used on your website.
( it was being used in the website from the other support thread )
The code to carry over the "Industry Categories", "Project Categories", and "Skill Categories" terms from the parent to the child post, would look like this:
add_action('cred_save_data', 'func_set_parent_terms_to_child',20,2);
function func_set_parent_terms_to_child($post_id, $form_data){
// if a specific form
if ($form_data['id']==5369) {
// get parent post ID
$parent_post_id = $_GET['parent-project-prompt1-id']; // adjust your parent post ID here
if(!empty($parent_post_id)) {
// get "Industry Categories" terms from parent and set to the child
$parent_terms_industry_categories = get_the_terms( $parent_post_id, 'Industry Categories' );
if(!empty($parent_terms_industry_categories)) {
foreach ( $parent_terms_industry_categories as $parent_terms_industry_category ) {
$parent_terms_industry_category_ids[] = $parent_terms_industry_category->term_id;
}
if(count($parent_terms_industry_category_ids)) {
wp_set_post_terms( $post_id, $parent_terms_industry_category_ids, 'Industry Categories' );
}
}
// get "Project Categories" terms from parent and set to the child
$parent_terms_project_categories = get_the_terms( $parent_post_id, 'Project Categories' );
if(!empty($parent_terms_project_categories)) {
foreach ( $parent_terms_project_categories as $parent_terms_project_category ) {
$parent_terms_project_category_ids[] = $parent_terms_project_category->term_id;
}
if(count($parent_terms_project_category_ids)) {
wp_set_post_terms( $post_id, $parent_terms_project_category_ids, 'Project Categories' );
}
}
// get "Skill Categories" terms from parent and set to the child
$parent_terms_skill_categories = get_the_terms( $parent_post_id, 'Skill Categories' );
if(!empty($parent_terms_skill_categories)) {
foreach ( $parent_terms_skill_categories as $parent_terms_skill_category ) {
$parent_terms_skill_category_ids[] = $parent_terms_skill_category->term_id;
}
if(count($parent_terms_skill_category_ids)) {
wp_set_post_terms( $post_id, $parent_terms_skill_category_ids, 'Skill Categories' );
}
}
}
}
}
Ref:
https://developer.wordpress.org/reference/functions/get_the_terms/
https://developer.wordpress.org/reference/functions/wp_set_post_terms/
Please activate this code snippet to run always and not just on-demand.
Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/
Waqar,
Thanks a ton for this. I ran the code you shared and the taxonomies still don't populate. I looked at the syntax and it looks fine. The code snippet is activated and can run anytime.
I also tried to use [wpv-post-taxonomy type='skill-category' separator=', ' format='name' show='name' order='asc'] to see if the taxonomy were populated in the backend but no data was retrieved. I went to the post in wordpress and saw that the checkboxes for categories in the submission were not checked.
Name of the project submission post: Taxonomy Transfer Test2
I am not sure what am I missing. You can look at this GIF here to see the flow: hidden link
Thanks!
Himanshu
To troubleshoot why the taxonomy terms are not getting attached, I'll need a clone/snapshot of your website.
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )
Note: I've set your next reply as private.
I'm sorry I forgot that you're hosted at wordpress.com.
They do allow the "All-in-One WP Migration" plugin and I'm downloading the backup package using it now.
I'll keep you updated with my findings.
During troubleshooting on your website's clone, I was able to make the code snippet work, using the following changes:
1. I disabled the option "Submit this form without reloading the page (use AJAX)" from the "Project Submission Form".
2. I replaced the taxonomy titles with their slugs, in the code that I shared earlier:
add_action('cred_save_data', 'func_set_parent_terms_to_child',20,2);
function func_set_parent_terms_to_child($post_id, $form_data){
// if a specific form
if ($form_data['id']==5369) {
// get parent post ID
$parent_post_id = $_GET['parent-project-prompt1-id']; // adjust your parent post ID here
if(!empty($parent_post_id)) {
// get "Industry Categories" terms from parent and set to the child
$parent_terms_industry_categories = get_the_terms( $parent_post_id, 'industry-category' );
if(!empty($parent_terms_industry_categories)) {
foreach ( $parent_terms_industry_categories as $parent_terms_industry_category ) {
$parent_terms_industry_category_ids[] = $parent_terms_industry_category->term_id;
}
if(count($parent_terms_industry_category_ids)) {
wp_set_post_terms( $post_id, $parent_terms_industry_category_ids, 'industry-category' );
}
}
// get "Project Categories" terms from parent and set to the child
$parent_terms_project_categories = get_the_terms( $parent_post_id, 'project-category' );
if(!empty($parent_terms_project_categories)) {
foreach ( $parent_terms_project_categories as $parent_terms_project_category ) {
$parent_terms_project_category_ids[] = $parent_terms_project_category->term_id;
}
if(count($parent_terms_project_category_ids)) {
wp_set_post_terms( $post_id, $parent_terms_project_category_ids, 'project-category' );
}
}
// get "Skill Categories" terms from parent and set to the child
$parent_terms_skill_categories = get_the_terms( $parent_post_id, 'skill-category' );
if(!empty($parent_terms_skill_categories)) {
foreach ( $parent_terms_skill_categories as $parent_terms_skill_category ) {
$parent_terms_skill_category_ids[] = $parent_terms_skill_category->term_id;
}
if(count($parent_terms_skill_category_ids)) {
wp_set_post_terms( $post_id, $parent_terms_skill_category_ids, 'skill-category' );
}
}
}
}
}