I'm using this statement to display a link if the field isn't empty:
[wpv-if url="wpcf-my-url" evaluate="!empty($url)"]
[types field="my-ur" title="Visit the page"][/types]
[/wpv-if]
Now we've noticed that some data is inccorect: the urls are missing a leading 'hidden link' - is it any way to $url to see if it contains 'hidden link' ?
For example (psudocode):
<cite>
I'm using this statement to display a link if the field isn't empty:
[wpv-if url="wpcf-my-url" evaluate="!empty($url)"]
[types field="my-ur" title="Visit the page"][/types]
[/wpv-if]
Now we've noticed that some data is inccorect: the urls are missing a leading 'hidden link' - is it any way to $url to see if it contains 'hidden link' ?
For example (psudocode):
[wpv-if url="wpcf-my-url" evaluate="!empty($url)"]
[wpv-if url="wpcf-my-url" evaluate="contains($url,'<em><u>hidden link</u></em>')"]
[types field="my-ur" title="Visit the page"][/types]
[/wpv-if]
[wpv-if url="wpcf-my-url" evaluate="!contains($url,'<em><u>hidden link</u></em>)"]
<a href="<em><u>hidden link</u></em> field="my-url" raw="true][/types]">Visit the page</a>
[/wpv-if]
[/wpv-if]
My psudeo-code got formatted strange: attaching a image here 🙂
Dear Christian,
A url field should always have the protocol in front (hidden link). What you can do is to enable URL validation in that field so that an error message will be displayed if http:// is missing.
Please let me know if there is anything else that I can assist you with.
Regards,
Caridad
Caridad: thanks, but in this I don't have control of the source data. Sure it is possible to modify the database directly or using a meta field filter - but I was wondering if it is possible to solve it using a substring matching in the template.
If not, it's fine - but since the feature could also be useful in many other cases (not directly related to urls).
Just to make sure - there is no way to do a substring matching using wpv-if?
Dear Christian,
No, there isn't. I can only see the empty() function working in there. What you can do is to attach to a filter and do the evaluation yourself, something like this should work in functions.php of your theme:
add_filter('wpv-extra-condition-filters', 'wpv_add_time_functions');
function wpv_add_time_functions($value) {
$value = eval('return (' . $value . ');');
return $value?'1=1':'1=0';
}
You have to use normal PHP syntax this time:
[wpv-if url="wpcf-my-url" evaluate="substr($url,0,7)!='<em><u>hidden link</u></em>'"]<em><u>hidden link</u></em> field="my-url"][/types]
Please let me know if there is anything else that I can assist you with.
Regards,
Caridad
@caridadz - ah, a real sweet solution (even if I can't let the users use raw php code in this particular case). Thanks 🙂