Skip Navigation

[Resolved] Post Reference Field Filtering Posts By One To Many Relationship With Page

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

Assisted by: Beda.

Author
Posts
#1245242

Hi Toolset,

I've got a Form integrated into a CPT (showcasing locations) Within the form the enduser needs to select a post while going through a signup process.

I'd like the options within the 'Post Reference' cred_field to be filtered by the one-to-many post relationship. I'd like the posts that already have a relationship to the locational page to be the only options within the 'Post Reference' cred_field.

Thanks in advance!

#1245308

It's natively not possible.

The Relationships Fields let you filter possibly to relate posts by the current user (authorship) or all posts of that type. This is the same for Post Reference Fields, you can only filter by authorship of the current user.

You'd have to submit a Feature Request at https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/, asking for a way to add your own custom Query to those input Fields, so you could (for example) let a View populate the Field, or a Custom Code hooked to a filter in our codebase.

Currently, there is no other way to achieve this, and it will also be challenging with Custom Code since all those filters we have (which are undocumented) should return either a post author ID or the keyword '$current'. Hence, they cannot return a post-relationship or other data for the query.

I'm afraid like this you can not limit the PRF (Post Reference Field), currently.

You'd have to populate a Generic Checkboxes Field, for example, populated by a View returning the desired Posts data in a valid JSON format.
Then, with a cred_save_data() snippet you could grab the values (let's say post ID's) from that field, and update the Post's PRF Field with that value using the Toolset API, which can be used also to either connect, get connected, or disconnect posts.
For updating PRF fields (which are Custom fields), you'd still use the above API (toolset_connect_posts()).

Here is the related Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data