Skip Navigation

[Resolved] Unable to Transfer Terms using relationship field value in post form

This thread is resolved. Here is a description of the problem and solution.

Problem:

I want to add the terms from project prompt post type to project submission post type on submitting project submission form. I am able to do that with url param as parent post id but I am unable to do that using $_POST("@relationship-field-slug.parent"). What am I missing? Is the slug for getting data from relationship field in a form different?

Solution:

Please try the PHP post variable:

$_POST['@project-prompt-to-project-submission_parent']
See PHP document:

Relevant Documentation:

https://www.php.net/manual/en/language.variables.external.php

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

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/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by himanshuS 4 years ago.

Assisted by: Luo Yang.

Author
Posts
#1904317
relationship slug.png

I have two post types : project prompt and project submission.

I want to add the terms from project prompt post type to project submission post type on submitting project submission form. I am able to do that with url param as parent post id but I am unable to do that using $_POST("@relationship-field-slug.parent"). What am I missing? Is the slug for getting data from relationship field in a form different?

I want to give the user an ability to change the parent post even if the url parameter provides a default value. That's why I need to transfer terms based on parent id in post form and not url param.

Project submission form screenshot attached.

Code below:

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 from url param
$parent_post_id = $_POST['@project-prompt-to-project-submission.parent']; //get parent post ID from form
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' );
}
}
}
}
}

#1904865

Hello,

Please try the PHP post variable:

$_POST['@project-prompt-to-project-submission_parent']

See PHP document:
hidden link

Dots and spaces in variable names are converted to underscores. For example <input name="a.b" /> becomes $_REQUEST["a_b"].

#1905653

It worked like a charm. Thank you!

#1905655

My issue is resolved now. Thank you!