Skip Navigation

[Resolved] Add parent type slug to child type field to support permalink manager

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by MrHinsh 1 year, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2605599

*Desired Outcome:*

I would like to have my child "Training" custom type URL be under the parent "Course" URL.

hidden link;

e.g.
hidden link
hidden link

Details:

I do not believe there is a way to do this out of the box with Toolset. (If there is then please let me know)

I believe that I can leverage the Permalink Manager plugin to add any fields on a custom post type to the Permalink structure.

New Permalink for Training: training/courses/__parent_slug/%trainings%/

For this to work the "Training" post type would need to have a custom field that holds the slug from the parent "Course" type. I would like to add some PHP using the Snippet plugin to my site that populates a custom field called "parent_slug" to any post type that has a parent added.

Question 1:

Is there a way to hook into the "add relationship" event so that I can update this field when the relationship is added?

Question 2:

How do I parse the parent work item to get its data when doing the update to the "training".

note: no access to our environment is required, nor will be provided, to answer these questions about toolset, its features, and its API.

#2605655

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

What if you try to use the Toolset hook "toolset_association_created" and add your desired custom code to update the value of your custom field:

add_action( 'toolset_association_created', 'func_update_child_custom_field', 10, 5 );
function func_update_child_custom_field( $association_slug, $parent_id, $child_id, $intermediary_id, $association_id ) {
    // Check against the post reference field slug.
    if ( $association_slug == "your-post-relationship-slug" ) {
            // execute the code to update the post's title
    }
}

Where:
- Replace "your-post-relationship-slug" with your original post relationship slug

Read more about it here https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_association_created

OR

You can use the save_post, please check the following tickets that may help you:
- https://toolset.com/forums/topic/auto-generate-post-title-based-on-parent-title/#post-1492773
- https://toolset.com/forums/topic/field-group-title-in-php/#post-1595451

#2607139

My issue is resolved and support was awesome. I ended up using the linked examples to create both a "toolset_association_created" and a "Cron" job to populate this data...