Skip Navigation

[Resolved] Filter child post based on parent taxonomy – but not grouped by parent post

This support ticket is created 7 years, 3 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 1 reply, has 2 voices.

Last updated by Beda 7 years, 3 months ago.

Assisted by: Beda.

Author
Posts
#554157

I created one CPT for markets (post type: "Markt") as parent-post and one CPT for services offered by the markets (post type: "Angebot") as child-post. Parent and child post type have both the custom taxonomy "Region" assigned. Starting from the parent-post I have created a link to a CRED post form to create the child-post which automatically links to the parent post.

Question: How can I copy the already selected values of the parent-post region-taxonomy , into the child post region-taxonomi field?

Rational for the copy: I want to enable the Relevanssi text-search of the child post to enable the search for "Region" as well as offering to selext from a drop-down list.

#554182

You cannot set it automatically, but you can display the Taxonomy Term name, or slug, or others, on the CRED Form.
With this information, it's easy for the user of your form to fill the form correctly.

Or, you could even populate a Generic Single Line Field with this Term Information, and then use it when you submit the Form, with a CRED API hook, to wp_set_post_terms() the Term of the newly submitted post.

1. This is how you display the Term of the Parent Post on the CRED Form that creates the Child Post:

- Create your Parent/Child relationship
- Create the Form that creates the Child Posts.
- Make sure, it includes a ShortCode for the parent post term as this example:

[wpv-post-taxonomy type="category" format="slug" id="[wpv-search-term param='parent_toolset-type_id']"]

==> We get the term slug of the post with id equal to the search term that CRED Child Post Forms add to the URL
- Add the "Create Child Post" Link to the actual Parent Post
- Add the "Create Child" FORM to any page and make sure, "Create Child Post" Link links to it
- When you now click on the "Create Child Post" Link you will get a URL like:

<em><u>hidden link</u></em>

- You will also see the Slug of the Term assigned to the parent Post on the CRED Form!

2. How to use the parent post term to populate a Generic Field and update the post with the term on submit:

- Insert a CRED generic Single Line Field to the form and populate the value with this:

[wpv-post-taxonomy type="category" format="slug" id="[wpv-search-term param='parent_toolset-type_id']"]

- Add a CRED API hook that gets the above Field value from the $_POST
- The same hook now should wp_set_post_terms() the new post with the value you got from $_POST

DOC:
https://developer.wordpress.org/reference/functions/wp_set_post_terms/
hidden link
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data