My code below is not outputting the values. I think it has something to do with how I’ve concatenated the echo strings. If I strip away the HTML tags it will output, but I need to add styling.
Is there a better way to achieve this?
<?php
$location = get_post_meta( get_the_ID(), 'location', true );
$date = get_post_meta( get_the_ID(), 'date', true );
$season = get_post_meta( get_the_ID(), 'season', true );
if( !empty( $location ) && !empty($date) && !empty($season) ) {
echo '<div class="post-extras">';
echo '<p>' . 'Wedding Location: ' . $location . '</p>';
echo '<p>' . 'Shoot Date: ' . $date . '</p>';
echo '<p>' . 'Season: ' . $season . '</p>';
echo '</div>';
}
?>
well you can do it like this as well.
Update
and to debug it, you add something like this so you are sure you are getting the right values, or any values out of the get_post_meta
and in case you only want to show the values you actually have:: you can use this::
Yes there is:
This is called a Heredoc, and is particularly useful in PHP for printing/echoing blocks of HTML code with visible indentation. The ability to throw a variable in there is pretty useful too.