Skip Navigation

[Resolved] Adding parent taxonomy to child post erases association between posts

This support ticket is created 3 years, 10 months ago. 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.

This topic contains 2 replies, has 1 voice.

Last updated by himanshuS 3 years, 10 months ago.

Author
Posts
#1904175
no association.png
url param passed.png
project submission form setup.png

I have a two post types:
1) Project prompt and project submission.
Project prompt has three taxonomies - project-category, skill-category and industry category.

I want to pass taxonomies from parent to child and have been using the following code provided by toolset to get this done. The taxonomies are added from project prompt to project submission but the association between the post is removed.

What could I be missing?

Code from toolset:
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' );
}
}
}
}
}

Steps to reproduce: (use admin login)
1) Select a project prompt by going here: hidden link
2) Click on add project submission.
3) The parent post id is populated by url param and is disabled to change with JS
4) Submit the project submission. The submission is saved as draft and you are taken to project submission post.
5) On the post you see no terms that are being called from the parent
6) double check - go to the project submission you created on wordpress admin and look for association. There is none.

I have attached screenshots explaining the issue.

#1904225
Custom JS.png
relationships.png

Update:

None of the associations are forming at all. More images to provide context.

#1904251

Another ticket is managing same issue.