Skip Navigation

[Resolved] Conditional Shortcode Not Working with Related Post Fields

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

Problem:
Conditional Shortcode Not Working with Related Post Fields with Divi theme module

Solution:

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/conditional-shortcode-not-working-with-related-post-fields/#post-1084569

Relevant Documentation:
https://toolset.com/documentation/recommended-themes/toolset-divi-integration/displaying-fields-inside-any-divi-module/#displaying-fields-using-any-other-module

This support ticket is created 5 years, 8 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 8 replies, has 2 voices.

Last updated by devinH 5 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#1081787

I am trying to:

When I use this short code, it gives me what I'm looking for

[wpv-post-field name="wpcf-personal-email" item="@person-post.parent"]

When I tried to evaluate if the output of the previous shortcode is empty using the following code, I got no output, not even any debug message.

[wpv-conditional if="( '[wpv-post-field name="wpcf-personal-email" item="@person-post.parent"]' ne '' )" debug="true"]
Success!
[/wpv-conditional]

Link to a page where the issue can be seen:
It wouldn't have helped because there's no output

I expected to see:
Success!

Instead, I got:
No HTML output

#1082789

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

First of all - After checking debug information you shared with us, I found that you are using outdated Toolset plugins. We always recommend to run your site with latest stable release plugin version.

Could you please update ALL Toolset plugins to it's latest official released version.

*** Please make a FULL BACKUP of your database and website.***
You can download latest Toolset plugins from your accounts page:
=> https://toolset.com/account/downloads/

Once you update ALL Toolset plugins - Please try to use following code:

[wpv-conditional if="( '[types field='personal-email' item='@person-post.parent'][/types]' ne '' )" debug="true"]
Success!
[/wpv-conditional]
#1083191

Thanks for the reply. I updated my Toolset plugins and tried your code. Unfortunately it still doesn't work. I changed the relationship slug but the rest is the same

This code gives me the desired output:

[types field='personal-email' item='@article-author.parent'][/types]

but this code you provided me, doesn't output any HTML, not even debug info:

[wpv-conditional if="( '[types field='personal-email' item='@article-author.parent'][/types]' ne '' )" debug="true"]
[types field='personal-email' item='@article-author.parent'][/types]
[/wpv-conditional]

Please help, thanks.

#1083258

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - could you please share problem URL and access details where you are trying to display the shortcode with conditional output.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#1084569

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - while working with Divi you should always try to generate the shortcode.

I've changed the conditional shortcode as given under:

[wpv-conditional if="( '{!{types field='personal-email' output='raw' item='@article-author.parent'}!}{!{/types}!}' ne '' )" debug="true"]

in side conditional = [types field='personal-email' item='@article-author.parent'][/types]
[/wpv-conditional]

I can see now - its showing debug information as well as second instance of shortcode value.
=> hidden link

You should try to use: Toolset Shortcodes menu at top of the page and click on Fields and Views to generate the shortcode that works with Divi.

More info:
=> https://toolset.com/documentation/recommended-themes/toolset-divi-integration/displaying-fields-inside-any-divi-module/#displaying-fields-using-any-other-module

#1084840

Thanks Minesh. The code you provided worked.

However, there are issues regarding the Toolset Shortcode generator you mentioned.

Problem 1
It's not possible to generate the following code directly from the generator:

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

Because the menu doesn't list relationship as an option, and users can't enter anything non-numeric in to the "specify an ID" section, which means you'd have to specify a placeholder ID, say 99999, and then replace it with the relationship slug @article-author.parent after it's been generated.

Problem 2
Once you end up with the code:

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

You have no way to enter it into the conditional shortcode generator without manually editing the condition.

Anyway, my main problem has been resolved so thank you for that.

#1087131

I moved the Divi module block around in the builder, and the same shortcode that was working before stopped working.

Moments later, after saving the page template and refreshing a page, the shortcode worked again, only to stop working again moments later. Again, no shortcode was changed.

#1096738

So as I mentioned in my previous reply, the wpv-condition shortcode seems to be unreliable and works intermittently when a related post field is accessed.

I had a working wpv-conditional shortcode based on a related post field, it stopped working all of a sudden. This shortcode was put in a Divi code module.

I then created a Divi text module with the same shortcode, and it worked.

Please take a look at:
hidden link

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. The credential to access the site is the same as what I provided initially in the thread.

Thank you

#1096739

I'll create a new ticket since this one has been marked resolved.

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