Skip Navigation

[Résolu] CRED – using a view to conditionally display parent posts in dropdown selector

This support ticket is created Il y a 9 années. 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 réponses, has 3 voix.

Last updated by tony Il y a 9 années.

Assigned support staff: Luo Yang.



Hi Tony,

From what I understand:
1. the custom post types that are involved are 'Events' that have as parent 'Event type'
2. the CRED form your using is for editing 'Events' so we can only set the parents according to two types of relationship:
- the parent form wordpress
- and the child parent form Types.
In the second case we have available all the 'Event type' posts as the parent ->child relationship set from Types.

Now what you had setup was to use a view to retrieve the ID of certain 'Events' and pass these as options for the select that is supposed to be handling the 'Event type'.
This will not work with the code that is implemented because the code is matching the ID's and expects ID's that exist in the original select from the 'Events type' custom post type.

So a possible solution would be to change the view and instead of having a view selecting 'Events' have a view that selects 'Event type' the correct parent post type. With this you can filter the view according to what you want to display in order to pass only the filtered posts. However you need to use the 'Events type' as this is the parent for the 'Event'.

3. the correct name of the select field to reflect the custom post type 'Event type' would be
var $select = $('select[name="_wpcf_belongs_event-type_id"]');

One other possibility, I'm not sure if this is what you wanted to achieve, is to relate posts of the same type in this case 'Events'.
For this you can use the parent relationship of WordPress and the field to use in the custom js would be post_parent.
var $select = $('select[name="post_parent"]');
Like this you can filter the parents set by WordPress and so use the Events parent of Events with the view that you currently have in the form.

I've set this last option in your site and I think it is working correctly.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.



Excellent - it is the last condition I was trying to resolve and the replacement of the var $select line was what I was looking for.

var $select = $('select[name="post_parent"]');

Thank you - the support is first class and much appreciated.