Skip Navigation

[Resolved] If custom field is blank, add php logic so that the information is not displayed

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 9 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

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 kellyB-2 9 years ago.

Assisted by: Minesh.

Author
Posts
#296442
example-umbrella-org.png

I am trying to: Add a custom field to a custom archive.php page. If the field is left empty, I do not want it shown on the archive page. My custom field is a text field for umbrella organization.

The current area of code looks likes this:

<div class="entry-content">
		 <?php
			echo '<h4 class"umbrella"> <strong>Umbrella Organization: </strong>';
			echo types_render_field("umbrella-organization", array("argument1"=>"value1","argument2"=>"value2","argument2"=>"value2"));
			echo '</h4>';

What I would like to happen is have else/if logic for if the umbrella-organization field is empty not to show the h4 class field name of Umbrella Organization.

Also if there is an easier way to surface a field name, I'm up for suggestions too.

I visited this URL:

I expected to see:

Instead, I got:

#296553

Minesh
Supporter

Languages: English (English )

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

1)

<div class="entry-content">

$umbrella_organization"= types_render_field("umbrella-organization", array("raw"=>"true"));

<?php if ( ! empty( $umbrella_organization) ) { ?>
<h4 class"umbrella"> <strong>Umbrella Organization: </strong>
         <?php   echo  $umbrella_organization;  ?>
 </h4>
<?php } ?>

2)
if you are using types custom field, you can also use: "wpv-if"
=> https://toolset.com/documentation/views-shortcodes/#wpv-if
For example:

[wpv-if f1="wpcf-my-custom-field" evaluate="!empty($f1)" condition="false"]some default text..[/wpv-if]
#298875

Thanks - this worked. Just in case someone else can use this, there is a tweak to the provided code that makes it work.

<div class="entry-content">

<?php 

$umbrella_organization= types_render_field("umbrella-organization", array("raw"=>"true"));
 
 if ( ! empty( $umbrella_organization) ) { ?>
<h4 class"umbrella"> <strong>Umbrella Organization: </strong>
         <?php   echo  $umbrella_organization;  ?>
 </h4> 
<?php } ?>

The forum ‘Types Community Support’ is closed to new topics and replies.

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