Skip Navigation

[Resolved] Conditional stopped working after update

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

Problem:

Use wpv-conditional shortcode in WordPress blocks editor.

Solution:

You can use WordPress shortcode block or Toolset Conditional block to setup the wpv-conditional shortcode

Relevant Documentation:

This support ticket is created 2 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.

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 10 replies, has 2 voices.

Last updated by kaleeR-3 2 years, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2046633

I updated the plugins and a conditional formula stopped working afterwards.

[wpv-conditional if="( '[wpv-post-type]' eq 'wow-classic/news' )"]
<a href="/wow-classic/"><img src="/wp-content/uploads/2020/12/classic.png" alt="WoW Classic News" title="WoW Classic News"></a>
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' eq 'tbc/news' )"]
<a href="/tbc/"><img src="/wp-content/uploads/2020/12/tbc.png" alt="TBC Classic News" title="TBC Classic News"></a>
[/wpv-conditional]

#2047117

Hello,

How do you setup those custom post types "wow-classic/news" and "tbc/news"?

There should not be "/" characters in the post type slug, please check these:
1) Find and edit those two post types "wow-classic/news" and "tbc/news", make sure your are using correct slugs
2) Edit the codes you mentioned above, use the same post type slugs.

#2048421
toolset1.JPG

Those are the correct slugs, as I mentioned it was working perfectly until the most recent update.

Anyway, I've tried using both "wow-classic-news" and the one that was working until now which is in the rewrite "wow-classic/news" and neither are working. Attached a screenshot.

#2049863

Please try to output the [wpv-post-type] shortcode directly, test it in frontend, then use the frontend result in the [wpv-conditional] shortcode, and test again

#2050717

It outputs fine without the conditional in place.

#2050745

I understand what you mean now, took me a few.
However [wpv-post-type] outputs "wow-classic/news" and "tbc/news"

If I try to use [wpv-conditional if=" ( ( 'wow-classic/news' eq 'wow-classic/news' ) ) " ] it just outputs that result for everything.

#2051237

I have tried the same setting as your screenshot in my localhost(fresh WP installation + the latest version of Toolset plugins)
https://toolset.com/wp-content/uploads/2021/05/2048421-toolset1_1.jpg

The codes you mentioned above works just fine:

[wpv-conditional if="( '[wpv-post-type]' eq 'wow-classic/news' )"]
<a href="/wow-classic/"><img src="/wp-content/uploads/2020/12/classic.png" alt="WoW Classic News" title="WoW Classic News"></a>
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' eq 'tbc/news' )"]
<a href="/tbc/"><img src="/wp-content/uploads/2020/12/tbc.png" alt="TBC Classic News" title="TBC Classic News"></a>
[/wpv-conditional]

It does output different image on different post type.

So the problem you mentioned above is abnormal, please check these:
1) Add debug="true" attribute in [wpv-conditional] shortcode, try to debug the problem in your website:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-conditional

2) In case it is a compatibility problem, please deactivate all other plugins, and switch to WordPress default theme 2021, 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/

You can also provide a test site with the same problem, I need to test and debug it in a live website, thanks

#2052651

Thanks for the details, I have done below modifications in your website:
Edit the problem page:
hidden link
Replace the "Fields and Test" block with a shortcode block, copy/paste the same codes into it:

[wpv-conditional debug="true" if="( ( '[wpv-post-type]' eq 'wow-classic/news' ) ) " ]
<a href="/wow-classic/"><img src="/wp-content/uploads/2020/12/classic.png" alt="WoW Classic News" title="WoW Classic News"></a>
[/wpv-conditional]
[wpv-conditional debug="true" if="( '[wpv-post-type]' eq 'tbc/news' )"]
<a href="/tbc/"><img src="/wp-content/uploads/2020/12/tbc.png" alt="TBC Classic News" title="TBC Classic News"></a>
[/wpv-conditional]

It works fine, please test again, check if it is fixed, thanks

#2053515
toolset2.JPG

That outputs the conditionals correctly but breaks all the styling and seems to be adding a paragraph tag and two line breaks.

Is there any reason the recent update caused the "Fields and Test" block to stop working properly?

#2053525

I got it working, I used two conditional blocks, one for each post type.

Thanks

#2053527

My issue is resolved now. Thank you!

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