Skip Navigation

[Resolved] Only show header and value when custom field isn't empty

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
- 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/Karachi (GMT+05:00)

This topic contains 12 replies, has 3 voices.

Last updated by Ivo Kruchten 1 year ago.

Assisted by: Waqar.

Author
Posts
#2617935

Tell us what you are trying to do?
I made a page template for custom type and added this, to show values:
<h2>Additional info</h2>
[wpv-noautop]
<h3>Publication date</h3>
[types field='publicatiedatum' suppress_filters='true'][/types]
<h3>Languages</h3>
[types field='talen' suppress_filters='true'][/types]
<h3>Pages</h3>
[types field='aantal-pagina-s' suppress_filters='true'][/types]
<h3>ISBN</h3>
[types field='isbn' suppress_filters="true"][/types]
<h3>DOI</h3>
[types field='doi' suppress_filters='true'][/types]
[/wpv-noautop]

Is there any documentation that you are following?
Yes, I followed the conditional codes I found on Toolset webpages and in support communities, but it still doesn't work. I feel I am missing something.

What is the link to your site?
Page where all custom fields are filled in, and where all of them need to be visible:
hidden link

Page where "Page" and "ISBN" fields are NOT filled in, and where these fields need to be hidden:
hidden link

Hopefully it will be possible to hide these fields and headers.

Thanks in advance!

#2618247

Hi,

Thank you for contacting us and I'd be happy to assist.

You can wrap each field's heading and the shortcode in a non-empty conditional statement like this:


[wpv-conditional if="( !empty($(wpcf-publicatiedatum)) )"]
<h3>Publication date</h3>
[types field='publicatiedatum' suppress_filters='true'][/types]
[/wpv-conditional]

Here is a useful guide on this topic:
https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2618315

HI Waqar,

thank you for looking into this for us.

I have added your code:
<h2>Additional info</h2>
[wpv-noautop]
<h3>Publication date</h3>
[types field='publicatiedatum' suppress_filters='true'][/types]
<h3>Languages</h3>
[types field='talen' suppress_filters='true'][/types]

[wpv-conditional if="( !empty($(wpcf-aantal-pagina-s) )"]
<h3>Pages</h3>
[types field='aantal-pagina-s' suppress_filters='true'][/types]
[/wpv-conditional]

[wpv-conditional if="( !empty($(wpcf-isbn) )"]
<h3>ISBN</h3>
[types field='isbn' suppress_filters="true"][/types]
[/wpv-conditional]

<h3>DOI</h3>
[types field='doi' suppress_filters='true'][/types]
[/wpv-noautop]

But I have the same problem: in both instances, when the aantal-pagina-s and isbn field is empty or filled, the h3 header and value is not shown.

So it seems we are still missing something,
regards,
Ivo

#2618337

I saw I used a ")" too little.
I fixed it:
[wpv-conditional if="( !empty($(wpcf-aantal-pagina-s)) )"]
<h3>Pages</h3>
[types field='aantal-pagina-s' suppress_filters='true'][/types]
[/wpv-conditional]

But still in both instances, when the aantal-pagina-s and isbn field is empty or filled, the h3 header and value is not shown.

#2618357

Thanks for the update.

To troubleshoot this, you can include the debug="true" attribute in the conditional shortcode to see what the actual values being used by the conditional statement:
( ref: https://toolset.com/documentation/legacy-features/views-plugin/debugging-views-output/ )

Example:


[wpv-conditional if="( !empty($(wpcf-aantal-pagina-s)) )" debug="true"]

In case, you're still not able to make this work, you're welcome to share temporary admin login details, along with the link to the page where the condition is not working as expected.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2618359

the following debug info is shown:
####################
wpv-conditional attributes
####################
Array
(
[if] => ( !empty($(wpcf-publicatiedatum)) )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( !empty($(wpcf-publicatiedatum)) )
--------------------
--------------------
Converted expression: ( !empty('') )

I am not sure how to proceed with this info.

#2619023

Unfortunately, the debug information is not very conclusive, so I'll need temporary admin login details to troubleshoot this further.

Can you please share that in reply to this message?

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2619271

Hi Ivo,

Thank you for sharing the access details, but when I try to access the login page, it shows the 'Forbidden: You don't have permission to access this resource.' message.

If there are any extra security restrictions enabled for accessing the admin area, can you please temporarily disable them, during the course of this troubleshooting?

regards,
Waqar

#2619321

Ron

Hi Waqar,
I'm a colleague of Ivo. Temporarily disabling the firewall is not an option, I'm afraid.
Is it possible to set up a Zoom call so we can show you the problem?

Kind regards,
Johan

#2619571

Hi Johan,

I understand if temporarily disabling the firewall is not an option.

Can you please try these two alternative approaches for the conditional statements:

1. Using the actual field shortcodes:
( ref: https://toolset.com/documentation/legacy-features/views-plugin/using-shortcodes-in-conditions/ )


[wpv-conditional if="( '[types field='publicatiedatum' suppress_filters='true'][/types]' ne '' )"]
<h3>Publication date</h3>
[types field='publicatiedatum' suppress_filters='true'][/types]
[/wpv-conditional]

OR

2. Using the 'wpv-post-field' shortcode:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-field )


[wpv-conditional if="( '[wpv-post-field name="wpcf-publicatiedatum"]' ne '' )"]
<h3>Publication date</h3>
[types field='publicatiedatum' suppress_filters='true'][/types]
[/wpv-conditional]

All these 3 approaches that I've shared in this thread are working on my test website. Please make sure that the field slugs are correct and especially note the usage of the 'wpcf-' prefix in these examples.

In case the issue still persists, setting up of Zoom call won't be possible, I'm afraid. But you're welcome to share a screencast/recording of how and where these statements are being added in the admin area.

regards,
Waqar

#2619671

Hi Waqar,

it seems that it has something to do with the fact we use the codes within a Divi page template.
When i insert the shortcodes in the body of the post, it works, but when I use them in the template it doesn't work.

Displaying the values without wpv-conditional works, so it possible that the page template can see the values inside the post's custom field.

Any idea how to move forward?

Thanks!
regards, Ivo

#2620705

Thanks for writing back.

This seems to be related to the limitation at the Divi's end, where it can't properly recognize/process the shortcodes used within the attributes of another shortcode:
https://toolset.com/errata/shortcodes-with-attributes-populated-by-shortcodes-are-not-evaluated-properly-in-divi-global-modules/

As a workaround, you can create a new Toolset content template from WP Admin -> Toolset -> Content Templates and add this conditional content to that.

Next, you can load this content template in your Divi template through the 'wpv-post-body' shortcode:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-post-body )


[wpv-post-body view_template="template name"]

Note: You'll replace 'template name' with the actual name of the content template.

#2621055

Thanks to Waqar helping me in the right direction I have found a solution within the Conditional options of the Divi module.

I made 2 separate version of the text module, where I have written the Toolset shortcodes to display the values of the custom fields. 1 with the amount of pages and isbn nummber, and 1 without these 2 fields. In the Conditions tab of the module I have described when to show or hide the modules. show when isbn field has a value or when not.

I can send screenshots when needed.

Thanks again!
regards, Ivo

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