Skip Navigation

[Resolved] Evaluate a Condition

This thread is resolved. Here is a description of the problem and solution.

Problem:

Use custom shortcode within [wpv-conditional] shortcode.

Solution:

You can follow our document to setup the [wpv-conditional] shortcode

Relevant Documentation:

https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/

This support ticket is created 3 years, 6 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Sammut 3 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1785929

We create a shortcode that looks for a string in a URL path. It works fine.

[string-exists name="category"]

This shortcode is also registered in Toolset. However, when I added to a condition nothing happens. Is my syntax correct?

[wpv-conditional if="( '[string-exists name="category"]' eq 'category' )"] DO THIS [/wpv-conditional]

#1787001

Hello,

I don't see anything wrong in your syntax.
How do you setup the custom shortcodes [string-exists]?
Please provide detail steps to duplicate the same problem, I need to test and debug it in my localhost, thanks

#1787507
screen.png

Thank you!

The shortcode as follows:

add_shortcode('string-exists', 'string_exists_func');
function string_exists_func($atts, $content){
    extract(  shortcode_atts( array(
        'name' => '',
    ), $atts ));
    
    $url = '<em><u>hidden link</u></em>' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    $res = '';
	    if (strpos($url,$name) !== false) {
		    $res = $name;
	    }
    return $res;
}

and to test I loaded the shortcode in as the image shows. I also loaded it into the functions.

#1788353

Thanks for the details, I have tried the custom codes and the steps you mentioned above in my localhost with a fresh WP installation + the latest version of Toolset plugins, it works fine:
I can see the result "DO THIS" when URL has string "category".

So the problem you mentioned above is abnormal, please check these:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to wordpress default theme 2020, deactivate all custom PHP/JS code snippets, and test again

3) Also check if there is any PHP/JS error in your website:
https://toolset.com/documentation/programmer-reference/debugging-sites-built-with-toolset/

4) If the problem still persists, please provide database dump file(ZIP file) of your website, you can put the package files in your own google drive disk, share the link only, also point out the problem page URL, I need to test and debug it in my localhost, thanks
https://toolset.com/faq/provide-supporters-copy-site/

#1788871

Thank you. This is just odd. No conflicts but just not working on this site. We will investigate it closer.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.