Tell us what you are trying to do?
I want to count the number of characters in a custom field, and if less than 3 do not display the field.
Is there any documentation that you are following?
I searched Support issues but could not find it.
I tried using create_shortcode but that didn't work either.
Thanks,
Jeff
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Jeff
We are talking about outputting an existing field, not entering data, right?
This should be straightforward—registering the strlen function to be used in conditional shortcodes, then adding a conditional shortcode that uses it—but I'm having a problem getting it to work.
Give me a little more time to keep testing and I'll get back to you.
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Jeff
It turns out we have an issue using native PHP functions in conditional shortcodes: https://toolset.com/errata/issues-when-registering-and-using-php-functions-with-conditional-display-that-pass-less-than-2-arguments/
The workaround is to register a custom function that essentially does the same thing—return the number of characters—and use that.
So, add the following code to your site:
/**
* Calc string length for use in wpv-conditional
*/
function calc_len($str) {
return mb_strlen($str);
}
Then register the function calc_len for use in conditional shortcodes at Toolset > Settings > Front-end Content.
You can then use it like so:
[wpv-conditional if="( calc_len( [types field='arbitrary-text'][/types] ) gt 3 )"]
[types field='arbitrary-text'][/types]
[/wpv-conditional]
(In my example I have a Types string field with slug 'arbitrary-text'.)
My issue is resolved now. Thank you!