Passer la navigation

[Résolu] Determine how many values a custom field has

This support ticket is created Il y a 4 years, 3 months. 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 -

Fuseau horaire du supporter : Asia/Kolkata (GMT+05:30)

Ce sujet contient 1 reply, a 2 voix.

Dernière mise à jour par Minesh Il y a 4 years, 3 months.

Assisté par: Minesh.

Auteur
Publications
#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

Les langues: Anglais (English )

Fuseau horaire: 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";
}