Skip Navigation

[Resolved] Conditional Shortcode Stopped Working

This support ticket is created 6 years 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 15 replies, has 2 voices.

Last updated by Beda 4 years, 7 months ago.

Assisted by: Beda.

Author
Posts
#1096740

So as I mentioned in my other tickets, the wpv-condition shortcode seems to be unreliable and works intermittently when a related post field is accessed, at least for me.

I had a working wpv-conditional shortcode based on a related post field written in a Divi Code module, it stopped working all of a sudden. I then created a Divi Text module with the same shortcode, and it worked.

Please take a look at this URL on my dev site:
/integrating-design-construction-to-create-livable-homes-jilaire-soucy-wagner-maison-design-build/

If you edit the post template, you'll see two Bio blocks that display author bio. One is made with the Divi Text module and the other the Code module.

In the Text module:

{!{wpv-conditional if="( '{!{wpv-post-id item="@article-author.parent"}!}' ne '' )"}!}
<p>Text Module</p>
[wpv-view name="personal-bio" ids="{!{wpv-post-id item="@article-author.parent"}!}"]
{!{/wpv-conditional}!}

In the Code module:

{!{wpv-conditional if="( '{!{wpv-post-id item="@article-author.parent"}!}' ne '' )"}!}
<p>Code Module</p>
[wpv-view name="personal-bio" ids="{!{wpv-post-id item="@article-author.parent"}!}"]
{!{/wpv-conditional}!}

The code in the Text module works but not the one in the Code module, and yet they're the same code.

Please take a look at this.

Thank you

#1096760

Well, I see in both modules the output in the front end, once "Code Module" and once "Text Module"

The condition says to display each of when there is a parent.
And there is, it's ID 3901.
Please insert just the field into the editors, to see what you are checking upon.
(THIS IS the actual value:{!{wpv-post-id item="@article-author.parent"}!} you are checking upon)

Both are working, as far I see they correctly return the value within its condition because the condition is triggering it.
Since the comparison checks if that is empty (and it is not) it returns the value.

What do you expect the condition to do?

#1096800

You might think I'm lying but it definitely wasn't showing the code module part when I submitted a ticket. I didn't take a screenshot because it has my client's picture, in hind sight I should've just blurred it out.

I'll restore the site and see if I can recreate the issue and get back to you. Thanks.

#1096817

Sure, no problem.

I never thought you are lying, did I make the impression?
I just looked at the issue and did not see it happen, that is all.

Let us know if it happens again!

#1096852

Sorry, I wasn't offended or anything, i just meant that it was weird that the frontend output changed even though I didn't change anything.

I recreated the problem again, please see if you can see it on your end. I recorded a video and a screenshot which I will post right away.

Thanks

#1096859

I tried flushing server side cache but still got the same result.

I uploaded the video, Is there a way to post a private message? Thanks.

#1096913

Indeed, I saw the issue.
I then removed

<p>Code Module</p>

from the Code Module as that figured to be the only visible difference, saved "this" instead.
That made it work.

I inserted

<p>Code Module</p>

again, it still works.

So, I suspect this is an issue that occurs when you save this on the particular ISP or OS you are connected to and that breaks something, as that seems to be the sole difference left.
The sole other possible factor is the user if you have another user than I do, please can you try with mine so to confirm?
I can - as soon I save the CT, see the condition apply.

In case it's not the user, to solve this, please do this:
- replicate this issue again (I am sorry for this, tried to re.replicate the issue by re-saving the same values, I still cannot replicate it).
- then, instead of just the ShortCode for the condition, add debug="true" to it:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/debugging/
- After, let me know so I can see the (breaking) ShortCode's Debug information on the site.

I will then have a look at what it tells, and handle adequately
I may also need to grab a copy of the site, is this allowed (and possible, technically?)?

Thanks.

#1097152
#1097350

I do apologise that I earlier should have seen this:
https://toolset.com/forums/topic/conditional-shortcode-stopped-working/#post-1096740
You seem to use mixed markup ({!{ and [ shortcode brackets) while, in Page Builders, you would always use {!{ (that is as well what should be generated) while when not using the builder, you would use [.

Then, you also use double apostrophes everywhere, while instead, if you nest Shortcodes, you need to alternate double and single apostrophes. (It is done correctly in the conditional, but the view in it doesnt follow that principle)

So the correct code would be:

{!{wpv-conditional if="( '{!{wpv-post-id item="@article-author.parent"}!}' ne ' ' )"}!}
<p>Code Module</p>
{!{wpv-view name="personal-bio" ids="{!{wpv-post-id item='@article-author.parent'}!}"}!}
{!{/wpv-conditional}!}

However, that works only in the Text Module, I cannot make it work again as yesterday...

I am downloading the package now and will see what this is.

#1097393

1. Test One was to deploy the site and remove all modules but the 2 test Modules
2. Issue is resolved
3. I did not even need to edit the code even if a not technically correct syntax is used.
4. I do however notice and need to mention that you use mixed syntax quite often.
As a rule of thumbs, use the GUI. It will produce {!{ where needed ad [ where needed.

I tried to narrow down deleting which element solves the issue.
None. Simply it can not be solved by deleting each module, but it's solved if you delete all modules at once.

I see a massively customized install, which we cannot call an install where things break in a replicable, but an exceptional customization.

There are several (!) PHP errors on site, amongst others:

( ! ) Warning: Use of undefined constant FLYWHEEL_PLUGIN_DIR - assumed 'FLYWHEEL_PLUGIN_DIR' (this will throw an Error in a future version of PHP) in /Applications/MAMP/htdocs/duplicator/.fw-config.php on line 11
( ! ) Deprecated: Function create_function() is deprecated in .../plugins/fancy-facebook-comments/includes/class-fancy-facebook-comments.php on line 196
( ! ) Deprecated: Function create_function() is deprecated in .../flywheel-config/plugins/flywheel/disable-wordpress-core-update/disable-core-update.php on line 24
( ! ) Warning: Cannot modify header information - headers already sent by (output started at .../flywheel-config/plugins/flywheel/disable-wordpress-core-update/disable-core-update.php:25) in .../wp-admin/includes/misc.php on line 1126

I then stripped the whole site down and still cannot use Conditionals at all in the code module.

I seriously doubt my own ability to appreciate reality.
I - just as you - can swear it worked on the first attempt, didn't anymore on few others, did again later and now it's totally broken in the code module.
At least it's broken and stops playing with me/us

I will escalate this to the DEV next Monday after I re-iterate thru this once again to at least find some replicable steps locally on a fresh install.
For now, please use the Text Module.

BTW:
I am somehow positive I had reported a similar one in past where the issue is that the builders do not threat all modules the same way and we could not solve the issue on our end, however, we'll try!

Thanks a lot for the duplicate, which enables me to show proof of issue to the DEV.

#1098012

Thanks for the reminder. This is my first Toolset implementation, so I didn't know to use the shortcode generator. I started using it, but the problem with it is that I can't generate shortcodes such as:

{!{types field='personal-email' output='raw' item='@article-author.parent'}!}{!{/types}!} 

because the textbox for entering the item ID only allows numeric. Also there's no way to use the code above as a parameter in the conditional shortcode generator either.

On a different note, 3 of the 4 PHP errors are from my host's plug-in which can't be seen or disabled in the admin area; the other is just a non-critical Facebook comment plug-in.

I'm glad I'm not the only person seeing the problem now, thanks for looking into this, Beda.

#1099345

I replicated the problem on a clean install, and - whatever previously happened, and how, I am not sure - but I can confirm that HTML conditional simply does not work on Code Modules of the latest DIVI's Builder versions and Toolset.

I escalated the problem to the developers (we just fixed a similar issue, https://toolset.com/errata/conditional-shortcodes-are-being-malformed-when-inserted-in-page-builders-with-the-new-shortcode-format/).
We will look if we can fix this.

The "standalone" shortcodes work fine in the module, hence I think it shouldn't be too difficult to fix this.

#1100271

I just wanted to share the exact findings and a solution to the issue.

After a while, I found a proper way to replicate this in a stable environment.

Here are the steps:
1. Install DIVI, Types and Views
2. Create a CT
3. Edit that CT with the Page Builder of DIVI
4. Insert a Text Module with Visual Mode active (not text mode).
5. In the Text Module, insert any conditionally shown text:
{!{wpv-conditional if="( '{!{wpv-post-id}!}' eq '1' )"}!}This is shown if post ID is 1{!{/wpv-conditional}!}
6. Assign the CT to any post (change above condition in required).
==> The condition works fine.
7. Put the same condition to a Code Module in the DIVI builder/CT (you need to copy paste the code)
==> The condition in the Code Module works as well
8. Now change the Text Module to use "Text Mode" instead of "Visual Mode", save.
==> The Conditional in the Code module now is broken.
(It does not even output Debug info)

Other shortcodes work great in the Code module.

So the easiest solution, for now, is to use "Visual" mode in the Text Module, that should solve the problem

Can you confirm that as well on your end?

#1104721

Sorry for the late reply, I've been on the road. I'm currently using the text module in visual and it works for now. Will there be a fix for this issue in the future or is this a Divi issue?

Thanks

#1105305

I am not sure yet.
For now, I published this erratum for reference:
https://toolset.com/errata/html-conditional-divi-code-module/

Our developers will look into this as soon we can free space for this compatibility issue and we will then update the Erratum with either solutions or notifications.

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