Conditional Statements in WP_Query for Meta Box
-
Hi,
I am trying to add a WP_Query to the home page of a blog with a featured content area that shows either a youtube video or the post thumbnail with a conditional statement so if the meta data from a field is true display that, if thats not available show the featured image.Seems like it should be simple but here’s my actual code that just displays nothing on the front end:
<?php// the query $the_query = new WP_Query( 'category_name=featured&posts_per_page=3' ); ?> <?php if ( $the_query->have_posts() ) : ?> <!-- pagination here --> <!-- the loop --> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <?php the_title(); ?> <?php if ( rwmb_meta( 'youtube', true ) ) : ?> <?php echo rwmb_meta( 'youtube' ); ?> <?php else: ?> <?php the_thumbnail(); ?> <?php endif; ?> <?php endwhile; ?> <!-- end of the loop --> <!-- pagination here --> <?php wp_reset_postdata(); ?> <?php else: ?> <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p> <?php endif; ?>
Any help is greatly appreciated!
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Conditional Statements in WP_Query for Meta Box’ is closed to new replies.