Skip Navigation

[Resolved] Define a maximum number of items for a custom multiple field (variable per role)

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.

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
- 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 10:00 – 14:00 -
- - - - - - -

Supporter timezone: Pacific/Niue (GMT-11:00)

This topic contains 6 replies, has 2 voices.

Last updated by nelsonM-2 5 years, 9 months ago.

Assisted by: Yvette Oliveau.

Author
Posts
#1204056

I have a custom post type.
That custom post type has a custom field, which is multiple (an image field, for example).

Lets say I need to limit the quantity of repeated items for that field, depending on the current user's role?
What do you suggest?

thanks!

#1204433

Yvette Oliveau
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Pacific/Niue (GMT-11:00)

Hello

You wrote: "...Lets say I need to limit the quantity of repeated items for that field, depending on the current user's role?...

I need a bit more information to be able to find the right solution for you. But the general approach would require custom coding. You would need some logic to (a) limit the instances displayed or created. And (b) you would need custom code to retrieve the current user role.

Finally, you would need to (c) wrap these 2 bits of logic with conditional output

1. Clarifications on the requirements
1.1 Update or Display?
Do you mean to limit the items that are displayed? Or the number of items that are permitted to be added/uploaded?
1.2. Toolset Form or Backend Admin?
Would the update be done via a Toolset Form or do you envision the post type being updated in the backend admin screen?

2. Links of interest - where to start for logic pieces (a), (b) and (c)

2.1 Here are relevant threads I found related to limiting the number of repeating instances (a):
https://toolset.com/forums/topic/limit-number-of-multiple-instance-fields-2/#post-374531
https://toolset.com/forums/topic/repeaters/
https://toolset.com/forums/topic/show-only-first-n-number-of-repeating-fields/

2.2 And here is how you would integrate a custom shortcode to test the current user role which would then be used in a conditional shortcode to send the number of fields to show to you solution for point 3.1 above. (b)
https://toolset.com/forums/topic/conditional-display-based-on-user-role-of-post-author/#post-543582
https://toolset.com/forums/topic/displaying-different-posts-and-custom-fields-based-on-user-role/#post-952767

2.3 Conditional Output (c)
https://toolset.com/documentation/user-guides/conditional-html-output-in-views

I hope this orients you to how you would pull together a complete solution.

#1204447

Hello Yvette,

you're right, I should have added some more info. Here goes:

1.1 Update or Display?
I meant to limit the number of items that are permitted to be added/uploaded.

1.2. Toolset Form or Backend Admin?
Backend Admin.

The idea I get from your links of interest is that it's easier to do this this if I use Toolset CRED Forms instead of trying to alter the Backend admin behaviour - is that correct?

#1204520

Yvette Oliveau
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Pacific/Niue (GMT-11:00)

As with anything, I guess "it depends". = )

I also found tickets on our forum where you can hide the custom fields based on user role with Access. Which also looks somewhat straightforward until you think: no, I don´t want to hide the fields, I just want to disable them for input.
https://toolset.com/forums/topic/hiding-fields-form-edit-based-on-roles/

It is true, however, that using a FORM might give you more control and flexibility in what you can do.

#1204530

I've used Access control to fields,
but in this case hiding or disabling would not be a solution, as what I want is to let roleA add the maximum of 3 items, roleB add up to 5 and so on...

But I'll keep the FORM option in mind as probably being the best for this.

thanks!

#1204554

Yvette Oliveau
Supporter

Languages: English (English ) Spanish (Español ) French (Français )

Timezone: Pacific/Niue (GMT-11:00)

Ok - I agree ! Once you have a working prototype and you find you need more assistance, please open a new ticket on the forum.

Best wishes and happy coding.

#1204577

Tkank you, Ivette!