user2142725
user2142725

Reputation: 11

How to hide custom field text if field left blank

I have a site with a form created with gravity forms. The visitor fills out this form and it populates a custom post type. The fields that the user completes are custom fields that I have created with the plugin "Advanced custom fields".

The form has a series of questions that the user fills out, but will leave some blank, as they are not all required.

This is the code used for the output:

I need to figure out how to hide the text 'Birthday' if the birthday field is left blank.

Upvotes: 1

Views: 833

Answers (1)

acmb3
acmb3

Reputation: 21

You should be able to do this:

<?php 
if( get_field( "birthday" ) ) {
    the_field( "birthday" );
}
?>

Source: http://www.advancedcustomfields.com/resources/functions/the_field/

Upvotes: 1

Related Questions