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

Who is Participating?
adrian7474Author Commented:
I got it. Answered my own question. I added this to the arguments:

$args = array( 'post_type' => 'my_post_type', 'meta_key' => 'my_meta_key', 'true', 'posts_per_page' => 1 );

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.