Skip Navigation

[Resolved] Hide button linked to a type when empty

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

Problem:
How to show or hide custom field when it's empty or does not contain any value within content template

Solution:
View's offers [wpv-conditional] shortcode to display conditional HTML output.

You can find proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/hide-button-linked-to-a-type-when-empty/#post-607418

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#url

This support ticket is created 6 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
- 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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Charles 6 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#607364

Support,

I am using the following code:

  <div class="row readmorewrapper">
	<div class="col-sm-5 readmorebutton">
      <h6 class="mtn mbn readmore"><a href="[wpv-post-url]">Read more</a></h6>
    </div>
	<div class="col-sm-5 purchasebutton">
      <h6 class="mtn mbn readmore">[types field='amazon-url' title='Purchase' target='_blank'][/types]</h6>   
    </div>
  </div>

I'd like to hide .purchasebutton if the types field is empty.

Screenshot of current code: hidden link

Screenshot of code removed through the inspector (what I'm trying to achieve): hidden link

I tried using:
.purchasebutton:empty {
display: none !impmortant}
but that did not work since it contains a H6.

Is it possible to show/hide the .purchasebutton using conditionals?

Thanks,
Chuck

#607418

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Yes - using Toolset you can display conditional output based on your Types field using [wpv-conditional] shortcode.

For example :

<div class="row readmorewrapper">
  <div class="col-sm-5 readmorebutton">
    <h6 class="mtn mbn readmore"><a href="[wpv-post-url]">Read more</a></h6>
  </div>
[wpv-conditional if="( '[types field='amazon-url'  output='raw'][/types]' ne '' )" ] 
  <div class="col-sm-5 purchasebutton">
    <h6 class="mtn mbn readmore">[types field='amazon-url' title='Purchase' target='_blank'][/types]</h6>   
  </div>
[/wpv-conditional]
</div>

More info:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#url

#607795

This worked!

Thank you,
Chuck