Skip Navigation

[Resolved] Pass Parent Taxonomy to Child Post Creation

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

Problem:

I have a parent post - Position

I have a child post - Application

When submitting an application for a position for an application, I want the Group (taxonomy) from the Position to be passed on to all of the Applications. The usual method for setting default values within cred/forms isn't working for checkboxes.

Solution:

It is achieved by using custom codes, see details here:

https://toolset.com/forums/topic/pass-parent-taxonomy-to-child-post-creation/#post-1141263

Relevant Documentation:

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

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 16 replies, has 3 voices.

Last updated by Sean 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1135217

I've searched, but nothing quite matches what I'm trying to do.

I have a parent post - Position
I have a child post - Application

When submitting an application for a position for an application, I want the Group (taxonomy) from the Position to be passed on to all of the Applications. The usual method for setting default values within cred/forms isn't working for checkboxes.

value='[wpv-post-taxonomy type="group" format="slug" id="$position"]'

What is the proper method for this?

{strangely, this worked fine until a few months ago when something was updated. no idea what that was}

#1135895

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - Can I have problem URL and access details where you want to pass the parent taxonomy IDs to child post?

#1136695

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I see you must be using Types version 3.X.X and you did not migrate to the new relationship.

With the release of Types version 3.0 before a few months back, it was a major release with the implementation of new many to many relationships.

Before you try to migrate to a new relationship:
*** Please make a FULL BACKUP of your database and website.***

Please check following docs carefully:
=> https://toolset.com/2018/05/when-if-to-migrate-relationships-in-old-toolset-sites/
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/

Once you decided it, migrate to new relationship and use the autogenerate form button to generate your form with latest forms version. Obviously keep backup your form anyway.

#1137007

I have updated the relationships and the code for my form.
The issue remains exactly the same.

#1137513

Hi,

Minesh isn't available, he has one day vacation, you will get the response ASAP when he back on Thursday.

#1138165

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I see you are using multi-site and could you please make sure you are using all latest Toolset plugins or all Toolset plugins must be updated to the latest official released version.

*** Please make a FULL BACKUP of your database and website.***
You can download the latest Toolset plugins from:
=> https://toolset.com/account/downloads/

#1138197

All of the plugins are already up to date.

#1138215

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - there is something missing than, with latest Toolset Forms plugin, when you click on "Auto-Generate Form" button the popup will look like as per the screenshot:
=> hidden link

But currently its not and I do not able to see which plugins you are using with your site.

#1138306

Apologies. Looks like the plugin failed to notice updates were available.
I've updated everything to the latest version manually.

#1138822

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Great - now when I try to access the form - it says the "Admin Guru" has taken over and is currently editing.

Could you please now "Auto-Generate" the form - do not forget to take your existing form code back up and adjust your form fields default values wherever needed and try to resolve your issue.

#1139081

I am no longer editing the form, so you can access it.
I already updated the form with an auto-generation and then integrated my necessary changes.
The problem persists.

#1140345

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - the group taxonomy is not remain selected based on the parent post taxonomy assigned because it returns the slug and we need term ID to set the selected term in group drop-down box.

I need FTP access details to site so that I can add the custom shortcode that returns the term ID and based on that term ID we can make the group drop-down box option selected based on parent post taxonomy term.

Could you please share FTP access details to site.

I have set the next reply to private which means only you and I have access to it.

#1141263

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To get the parent taxonomy term ID, I've added following code at: Toolset => Settings => Custom Code => toolset-custom-code section:

function func_get_parent_term_ids( $atts ){
   	$parent_id = 0;
    if(isset($_GET['parent_position_id'])){
        $parent_id = $_GET['parent_position_id'];
        $term_ids = wp_get_object_terms(  $parent_id, 'group', array( "fields" => "ids" ) );
        return join('',$term_ids);
    }
}
add_shortcode( 'get_parent_term_ids', 'func_get_parent_term_ids' );

I've added following hidden field to your form:

[cred_generic_field type='hidden' field='tax_parent_group_term_id']
{
"default":"[get_parent_term_ids]"
}
[/cred_generic_field]

And I've added following custom JS to your form's JS box:

jQuery(document).ready(function($){
  value = $('input[name="tax_parent_group_term_id"]').val();
  $('select[name="group[]"] option[value="'+value+'"]').attr("selected","selected");
});

Now, when the form is loaded, I can see the select dropdown loaded with selected parent term:
=> hidden link

Could you please confirm.

#1143278

That does indeed work on my test site, thank you.
It is broken on my live site, however. I've opened another ticket explaining the issue:
https://toolset.com/forums/topic/custom-code-broken-due-to-javascript-error/

I'll attempt some workarounds in the meantime.

#1143681

Hi,

Minesh isn't available, I assume the original question of this thread is resolved, for the new question, please check your new ticket:
https://toolset.com/forums/topic/custom-code-broken-due-to-javascript-error/

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