Equivalent to compare='LIKE'


Im struggling to set my If statement to check if the value is in the custom field as a value anywhere when the values are comma-separated.

e.g. Field = country with values = gb, de, us, ca

My L&L only works if one value is listed in my custom field, not multiple.


I’ve tried all logical compare

How it works in a wp_query

‘key’ => ‘countries’,
‘value’ => ‘gb’,
‘compare’ => ‘LIKE’

Hopefully something obvious I’ve missed.


Short answer: I believe the in comparison is the one you’re looking for.

Long answer: assuming this is still the same use-case as your previous post and assuming you’re using my somewhat-hacky <Format case=kebab> to make your lowercase variable, the reason this wouldn’t work with an array in your variable is that kebab case will format the string GB,DE,US,CA as gb-de-us-ca but hyphens aren’t interpreted as an array. If there was a <Format case=lower> option then that’d be the best way to go for you. You might consider making a feature request for that. Edit: as per Eliot’s comment below, lower case text formatting is now possible in the latest version of the plugin! So the solution below is no longer necessary.

In the meantime, you could theoretically just nest two Format tags like this:

<Format replace="-" with=","><Format case=kebab>GB,DE,US,CA</Format></Format>

Which would output gb,de,us,ca which is an array that you could concatenate with your uppercase variable to write an If statement that compares against all the values in the array, both uppercase and lowercase. You should just be able to use the in comparison for that, so something like:

<If check="gb" in value="GB,DE,US,CA,gb,de,us,ca">
  gb is in the value array

Thanks for the suggestion, Ben - I added <Format case=lower> in the newest plugin version.

1 Like