Skip Navigation

[Resolved] Conditional display of custom fields

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

Problem:

I think it would be easier to edit so many conditional statements in the old editor but I tried converting the block into the tradition editor and I received a message saying there was no template and it would be reset and it did change the interface to the old views but I lost all the content. Is there any way I can see and edit the content in code somewhere?

Solution:

You can setup the [wpv-conditional] shortcodes with Toolset "Fields and Text" block, in the "Fields and Text" block menu, click the "IF" button, and setup conditions, insert the the [wpv-conditional] shortcodes into content, switch to HTML codes editor, then you will be able to see and edit the content in codes

See screenshot:

https://toolset.com/wp-content/uploads/2021/04/2017899-field_and_text.jpg

Relevant Documentation:

https://toolset.com/block-item/fields-and-text/

This support ticket is created 3 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
- 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 8 replies, has 2 voices.

Last updated by alistairW-2 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2014157
lines.jpg

Tell us what you are trying to do?
I have a lot of custom fields relating to a specific post. Many are blank. I want to display a list of all non-blank fields on a custom template. I have tried using conditional block with code such as...[wpv-conditional if=" NOT ( empty( $(wpcf-eyes)) ) " ] Eyes: [types field='eyes'][/types] [/wpv-conditional]. But not sure this is correct method AND this leaves blank lines in the resulting page when I dont want any line at all.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hidden link

#2014265

Hello,

I assume we are talking about this page:
hidden link

I have checked above page in my Chrome browser, those blank lines are outputted from HTML codes:

<p><span style="font-weight: 400;"></span></p>

These HTML codes are different from what you described above, I suggest you locate those HTML codes, try to remove them or wrap them into the [wpv-conditional] ... [/wpv-conditional] shortcodes, if you need assistance for it, please provide a test site with the same problem, fill below private message box with the test site credentials.

#2014279

Thanks Luo,

Yes that is the correct page. I'm not even sure I am doing this list correctly. Is there an easier way using the blocks to get a list of the custom fields but ignore the ones that are empty? (and not leave spaces where the empty ones should be?

#2014375

Within Toolset Blocks plugin, there is a built-in "Conditional Block", you can use it in the content template(Designed with Blocks editor), see our document:
https://toolset.com/course-lesson/using-toolset-conditional-block/

#2015277

Hey Luo,

THe challenge I have 26 custom fields that could be in the list. To use the conditional blocks to say only show a field if it is not empty would require me to add 26 conditional blocks ( [wpv-conditional] ... [/wpv-conditional] shortcodes) each controlling if a custom field is displayed. I cant see anyway to use one conditional block to control all the custom fields.

I have little coding experience but would not know what code to add and where, if that is a better route.

#2015509

I don't think there is other better rule for you, you just need to follow the document to setup the conditional blocks, and please let me know if you need more assistance for it.

#2016687

I think it would be easier to edit so many conditional statements in the old editor but I tried converting the block into the tradition editor and I received a message saying there was no template and it would be reset and it did change the interface to the old views but I lost all the content. Is there any way I can see and edit the content in code somewhere?

#2017899
field-and-text.JPG

You can setup the [wpv-conditional] shortcodes with Toolset "Fields and Text" block, in the "Fields and Text" block menu, you can add the "IF" button, and setup conditions, insert the the [wpv-conditional] shortcodes into content, switch to HTML codes editor, then you will be able to see and edit the content in codes, see my screenshot field-and-text.JPG

More help:
https://toolset.com/block-item/fields-and-text/

#2020037

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.