Skip Navigation

[Closed] Show text in condition with search string

This support ticket is created 3 years, 11 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 3 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1863639

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

#1863975

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.

#1864263

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]
#1864703

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/

The topic ‘[Closed] Show text in condition with search string’ is closed to new replies.