Skip Navigation

[Resolved] Restrict the relationship options to posts created by the current user

This support ticket is created 5 years, 9 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
- 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/Karachi (GMT+05:00)

This topic contains 5 replies, has 2 voices.

Last updated by davidS-53 5 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#1209874

I am trying to: Restrict the relationship options to posts created by the current user - as per this thread: https://toolset.com/forums/topic/restrict-the-relationship-options-to-posts-created-by-the-current-user/

Here's how I've got the select dropdown set up:

[cred_field field='@crew-member-crew-certificate.parent' select_text='--- not set ---' class='form-control' output='bootstrap' use_select2='never' author='$current']

I have already tried deactivating all plugins except for toolset and swapping back to 2019 theme, and the dropdown still shows all the crew members regardless of post author.

Any ideas where I might be going wrong?

#1209999

Hi David,

Thank you for contacting us and I'll be happy to assist.

As explained in the documentation of the "cred_field" shortcode ( ref: https://toolset.com/documentation/user-guides/cred-shortcodes/#cred_field ), if "use_select2" is set to "never", it breaks the atrributes like "order", "ordering" and "author".

At the moment these attributes are only supported, if Select2 field is enabled ( use_select2='always' ).

To make this functionality available in future releases, you're welcome to submit this as a feature request:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

I hope this helps.

regards,
Waqar

#1210315

Oh right, ok, that works. The docs are pretty confusing- "If used with new post relationships (Types 3,0+), it breaks the "order", "ordering" and "author" attributes."

It only breaks the attributes noted if you use "never" as the option for use_select2- perhaps be worth updating the docs to be clearer.

Cheers!

#1210435

Actually, while we're on the topic, is it also possible to restrict cred_field options by parent post ID? Let me explain:

Scenario: A Boat has many members (boat-crew-member relationship- one->many). Members have many certificates (crew-member-crew-certificate relationship- one->many). Take this data:

Boat 1 - Member 1
- Member 2
- Member 3

Boat 2 -Member 4
-Member 5
-Member 6

If I know the ID of boat 1, for example, could I restrict the

[cred_field field='@crew-member-crew-certificate.parent' select_text='--- not set ---' class='form-control' output='bootstrap' use_select2='never' author='$current']

dropdown to only Members that belong to boat 1- ie. User 1, 2 and 3? Does that make sense?

#1211710

Hi David,

Thanks for writing back and I apologize for the delay.

This kind of filtering won't be possible directly using the "cred_field" shortcode, but you can use a generic field that uses a custom shortcode, to generate the list of Members, as needed.

Note: the custom shortcode should return the options and the values for the generic select field in this JSON object format:


{"value": "value1", "label": "Label 1"}, {"value": "value2", "label": "Label 2"}

The example shared in this reply should make its usage more clear:
https://toolset.com/forums/topic/parent-cant-be-identified-without-grandparent/#post-1200437

To get personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

For each new question/concern, please open a new ticket.

regards,
Waqar

#1213483

Ahh great, yeah that makes sense. I think I've done a similar thing elsewhere so should be able to adapt that. Cheers!