I want to list some custom posts (wordpress) and their meta values. Everything works fine so far, but I have to work with empty values too. And I want to use slashes to separate multiple values. So here’s what I have so far:
$list = '<div class="clearfix vlist">
<div class="vlist-content">' ;
while($wpex_query->have_posts()) : $wpex_query->the_post();
global $post;
$list .= '<div class="vlist-item">
<div class="title">'.get_the_title().'</div>
<div class="info">'
.get_post_meta( $post->ID, 'wpex_vita_genre', true ).' / '
.get_post_meta( $post->ID, 'wpex_vita_director', true ).' / '
.get_post_meta( $post->ID, 'wpex_vita_role', true ).'</div>
</div>';
endwhile;
wp_reset_query();
return $list . '</div></div>';
Problem comes within div.info, where I want to display 3 values, separated by slashes (/). Soon as one or two values are empty I get stupid double slashes // because these characters are not conditional. I don’t know how to make them appear only when there are values to separate because I can’t just put an if statement into my $list. I know I know now you people who know php are just shaking heads or doing facepalms because this for sure is easy pie… could you still tell me how to solve this problem?
Thank you!!
I just came across the solution with the right use of conditional statements when defining the meta-values as variables, for example:
Simple. Still took me years to get it right. Maybe s.o. will save some seconds reading my solution 😀