A Cozmoslabs Product
Documentation / Custom Fields Creator / How to / Using Conditional Statements

Using Conditional Statements

Considering we have a Repeater Meta Box with the following fields: Event Name, Event Description and Event Date and we want to display the results only if the Event Name and Event Description are filled in:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php 
$event_list = get_cfc_meta( 'event_list' );
if( !empty( $event_list ) ){
   echo '<ul id="event-list">';
   foreach( $event_list as $key => $event ){
       $event_name = get_cfc_field( 'event_list','event-name', false, $key );
       $event_date = get_cfc_field( 'event_list','event-date', false, $key );
       $event_description = get_cfc_field( 'event_list','event-description', false, $key );
       if( !empty( $event_name ) && !empty( $event_date ) ){
           echo '<li>';
           echo '<div class="event-name">'. $event_name .'</div>';
           echo '<div class="event-description">'. $event_description .'</div>';
           echo '<div class="event-date">'. $event_date .'</div>';
           echo '</li>';
       }
   }
   echo '</ul>';
}
?>

The Ultimate Membership Bundle

Combine the power of Profile Builder with Paid Member Subscriptions to set up user registration, memberships, and recurring revenue.

Get 25% off with the bundle

Help & Support

We’re here to help you every step of the way.

Open a Support Ticket