Skip Navigation

[Resolved] Determine how many values a custom field has

This support ticket is created 3 years, 4 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 1 reply, has 2 voices.

Last updated by Minesh 3 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#2288119

I'm working on an old site that displays Toolset fields using PHP code. I know how to determine if a field has a value, but how can I check to see if it has more than one (before doing anything else). RIght now I am checking with:

if ( !empty( types_render_field( 'documents', array() ) ) ) {
...
}

But I want to determine if more than one document has been added (the field is set to allow for multiple) before it gets into the display code.

Thanks!
Bob

#2288403

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

To check how many number of instances of repeating field is there, you should try to use the following code:

$docs =  types_render_field( 'documents', array());
if ( count($docs) > 1 ) {
echo "it has multiple repeating field value";
}