Owen O'Neill
Owen O'Neill

Reputation: 205

Conditional Tag With Custom Fields Not working correctly

What I am after is to get the Date and title to appear on each Calendar if that Custom Field is filled in; but at the moment, it is putting them in order and displaying a calendar for every child page, but I only want a Calendar and date appear if they have an upcoming date.

Any help will be madly appreciated! - See link at bottom for working example.

This is what I have at the moment:

                <!-- PHP OF OPEN DAYS -->
<!-- Calender Items -->
<div class="calender-item">
<?php $values = get_post_custom_values("next_open_day");
            if ( is_array($values) )
                   the_field( 'university_name');
            else 
    echo '';
 ?>


<?php $values = get_post_custom_values("next_open_day");
            if ( is_array($values) )
                  the_field('next_open_day');
            else 
    echo '';
 ?>

<!-- END OF CALENDER ITEM -->   


</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>

Any idea's then shoot away please...

The way my site is spitting it out at the moment is like this:

http://universitycompare.net/open-days

Upvotes: 0

Views: 75

Answers (1)

Alexios Tsiaparas
Alexios Tsiaparas

Reputation: 910

Move the if above the div, that way it will not print at all when false

<?php $values = get_post_custom_values("next_open_day");
            if ( is_array($values) ) {
echo '<div class="calender-item">';
                   the_field( 'university_name');
                  the_field('next_open_day');
echo '</div>';
}
            else 
    echo '';
 ?>

Upvotes: 1

Related Questions