Skip Navigation

[Resolved] Unable to transfer parent taxonomy data to child post using reference post

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

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 15 replies, has 3 voices.

Last updated by himanshuS 3 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#1865113

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?

#1865153

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.

#1865155
snippet issue.png

Image attached.

#1865339

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.

#1867369

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

#1868071

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.

#1869673

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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

#1870259

Thanks Waqar. Looking forward to hearing from you.

#1875921

An update on the issue would be appreciated. Thank you.

#1875991

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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.

#1876627

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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/

#1877321

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

#1877839

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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.

#1878979

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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.

#1880299

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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' );
                }
            }
        }
    }
}

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.