I am trying to make a custom Query in Wordpress for posts that have a certain custom field, for example “vid” = true. I only want to display one post, but it doesn’t have to be the most recently posted post. It has to be the most recent post that has the meta value, but there can be dozens of posts with this meta value.
My question is, how can I filter out posts that don’t have this meta value and only display the most recent one? The problem I’m facing now is that the custom Query is taking the last post that was published, whether it has this meta value or not.
I would really really appreciate any help. Thanks. 
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();
$metaval= (get the meta);
if($metaval=="vid")
{
(display post);
break;
}
endwhile;endif;
?>
