Skip Navigation

[Resolved] Empty custom fields

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

Problem:
How to only output fields (and any labels) if the field has a value, specifically in Elementor templates.

Solution:
You wrap the relevant section inside wpv-conditional shortcodes, as described in the linked documentation, so that you have something like this:

[wpv-conditional if="( $(wpcf-architect) ne '' )"]
Architect: [types field="architect"][/types]
[/wpv-conditional]

When inserting in an Elementor template you need to make sure this is inserted in a module which parses shortcodes, such as the Text or Shortcode modules, but NOT the HTML module, which does not parse shortcodes.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

This support ticket is created 5 years, 10 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 7 replies, has 2 voices.

Last updated by johnh-18 5 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1186636

I have created a view with custom fields which is displayed in an Elementor template.
The question is if it is possible to create a filter so that only custom fields with a value is displayed on the front end, eg if a custom field is ‘Architect’ and the field is empty, Architect is not visible on the page.
I looked at the following page in the forum which seems to be very similar to my question but can not get it to work
https://toolset.com/forums/topic/hide-empty-custom-fields-on-post-type-model/
The page URL is hidden link
The site is under dev so it is password protected - login details are
username: tga
pw: Krit@45

#1186681

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi John

The requirement is, if a custom field for a post has no value, then don't output the label for the field, is that right?

That is described here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

You need to wrap the part where you insert a field, together with its label if you are manually adding that, in a conditional shortcode that first tests whether the field has a value or not.

In a text editor field, for example if creating a Views Content Template, you can use the "conditional output" button to insert the wpv-conditional shortcodes.

That's not available if you are using Elementor, you will need to manually enter the shortcodes in a text/html module.

#1186868

Hi Nigel,
Thank you for your message. Your first assumption is correct and I understand what you are saying but unfortunately, I do not understand how to implement.
Two questions
1. You write "In a text editor field, for example if creating a Views Content Template, you can use the "conditional output" button to insert the wpv-conditional shortcodes." Do I click the 'conditional output' button in 'Loop view' or in the section below, ie 'Templates for this View'?
2. Would you mind giving an example of a complete string for one custom field, eg the 'architect' field.
Best regards / john

#1188023

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi John

1. It doesn't matter, you are only using the conditional output button to help you generate the shortcode, which you will copy but then delete from wherever you were inserting it. You could then paste it into the required location in your Elementor template. (We can add modules to Elementor, but have no other control over their UI, so cannot provide the same buttons such as the Field and Views and conditional output buttons.)

2. An example of the resulting code for a field with slug "architect" (which Types stores with a 'wpcf-' prefix) would be:

[wpv-conditional if="( $(wpcf-architect) ne '' )"]
Architect: [types field="architect"][/types]
[/wpv-conditional]

You should be able to add that to a text or HTML module in your Elementor template.

#1188907

Hi Nigel,
Thank you for your message. I usually do not have a problem understanding these things but this time, it seems as if have to surrender (which is really annoying). Trying to follow your advice either displays the piece of code you used as an example or absolutely nothing.
A last attempt to get my head around this if you can think of an alternative way to explain this
- when trying to display the Toolset view - should I use the Toolset view app and then select the relevant view
OR
- should I use the separate short codes for each custom field (eg. Living space: [types field='living-space' item='$current_page'][/types] [types field='unit-living-space'][/types] )
- I am obviously not pasting the code you provided in the right place so where should it go - I have tried to past it into an elementor HTML field where the architect info should be and when that did not work, into a short code field.
Great if you could try one more time to explain. Failing that, do you know of any developer working with Toolset you can recommend?
Best regards / john

#1188961

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

John

Maybe I could just look at your site and see for myself why it's not working.

I'll mark your next reply as private so that I can get log-in credentials from you—you may want to create a temporary admin user for me to use that you can later delete. And be sure to have a current backup of your site, even though I don't intend to make any changes other than directly related to inserting this correctly.

And to confirm, this is an Elementor template for single property-for-sale posts, yes?

#1189073

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi John

I think the issue was quite simple in the end.

I double-checked on my own test site, and it seems that Elementor does not parse shortcodes in HTML modules.

So you need to insert the shortcodes for the fields into Text modules or Shortcode modules (which can also include text).

I deleted the HTML module where you conditionally added the architect and inserted it into a text module instead, and it now works.

While there I noticed that you were using the item="$current-page" attribute for the shortcodes for living space etc. which are not necessary, and I removed them.

As for the columns, it seems you already have that, but in any case that depends on the template you create with Elementor.

#1189623

My issue is resolved now. Thank you!