Skip Navigation

[Resolved] Filter cred field based on entry in another field

This support ticket is created 8 years, 2 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
- - 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)

Author
Posts
#417395

I have a few custom post types with relationships as follows:

*Teams
* Locations
* Location Fields (child of Location)
* Team Practices (child of teams / Locations / Location Fields)

On my CRED form to add a Team Practice, I have a field for location and one for location field. Is there any way to filter the location field to only those entries belonging to the Location I select (it's listed first on the form)?

#417564

Not natively.

The parent Post Pickers will always allow to pick ANY parent Post, just as in the WordPress Backend as well.

It would also be resource expensive to query the Child Posts of the chosen Parent Post, which is theoretically possible, but resource expensive and requires Full Custom Code.

You can see an example here how it's done with Authors (display only Posts by the same author as logged in user):
https://toolset.com/forums/topic/i-want-to-only-display-the-parent-items-of-the-current-user-in-a-select-box-2/#post-351830

You could adapt that Query that generates the [get-parents] shortcode.

But I do not recommend it, it is querying an eventually large amount of posts.

#417631

Thanks for the update. Could I accomplish something similar with a view and setting the CRED select fields recordsource to that view?

#417876

Not really.

There are 2 problems if you do it with a View:

1. Views is not a data provider but a data render engine.
Views does wrap the Loop in a default HTML div, that would break any JSON you produce with it, unless you apply a Custom Function to remove that div:
hidden link

2. You could still not let the View display posts according to the chosen parent, as Views does not have a filter for that.
You could, of course, hard code a Filter, but it would destroy the goal of the dynamic update / Display of your Selector Contents

The only possibility to achieve this is by above given Custom ShortCode that creates a Query and returns the Posts given a Parent that you choose previously in your Form.

This requires Custom Code, and it is resource expensive, I do not recommend this approach.
In case you want to follow this path, you could consider contacting one of our certified partners from this link:
https://toolset.com/consultant/

You will get the custom assistance you need to get on with your project.

#418083

Understood, thanks for getting back to me again. Might I suggest that an enhancement that leverages post type relationships for select fields is in order? I can't imagine I am the only person who would use something like this and there are plenty of use cases (many-to-many relationships especially) where this would make the presentation layer to an end user much friendlier. Thanks again.

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