Link to home
Start Free TrialLog in
Avatar of adrian7474
adrian7474Flag for United States of America

asked on

Loop the latest post-type that has a meta box checked only

I need to loop only 1 of the latest post-type post in my sidebar, however, I only want to loop the latest one that has a meta box checked. I use the metabox option to give the post-type two different looks (videos or photos).
I want to loop the photo type only and the problem is that if a video version of that post-type is the newest one, then it blows out the older one and displays nothing. Is there a way to do this by effecting the query arguments or something?

Here is what I have so far:

<?php $args = array( 'post_type' => 'my_post_type', '', 'posts_per_page' => -1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php   if(get_post_meta($post->ID, 'my_post_type', true)) : ?>	
<?php the_title(); ?>
<?php endif; ?>
<?php endwhile; ?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of adrian7474
adrian7474
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial