I need to show a message if the search string contains two hyphens:
This does not seem to work:
[wpv-conditional if="( CONTAINS('[wpv-search-term param='wpv_post_search']' eq '-' ))"]
Looks like you searched for hyphens
[/wpv-conditional]
I hope you can help me with that
Hello, the CONTAINS operator is usually used to compare values in an array against some other value. It's not helpful in this case because you want to check each character in the search string. Instead, you probably need to use the REGEX operator. If you're testing for a hyphen anywhere in the search string, that might look like this:
[wpv-conditional if="( '[wpv-search-term param='wpv_post_search']'=REGEX('-','i'))"]
Looks like you searched for hyphens
[/wpv-conditional]
For a more complex scenario, you would have to write a custom REGEX test based on your requirements for testing the hyphen positions within the search string. See some documentation for the REGEX operator here: https://toolset.com/documentation/programmer-reference/forms/cred-conditional-display-engine/
Custom regular expression development is a bit outside the scope of support we offer here, but there are online tools you can use to help craft one for your specific needs.
Thank you, that works great.
As I can see in the documentation, I'm limited to REGEX without square brackets.
Do you have an idea, why the following does not work? It should look for a search term that begins with two letters then comes a dash and then two numbers --> ZZ-11
[wpv-conditional if="( '[wpv-search-term param='wpv_post_search']'=REGEX('\D\D-\d\d','i'))"]
ZZ-11
[/wpv-conditional]
Not sure offhand, but if it's easier you could create a custom PHP function that evaluates the search term string against some PHP expression, and register that custom function in Toolset > Settings: https://toolset.com/documentation/programmer-reference/views/using-custom-functions-in-conditions/