1479 posts The right tools with none of the gimmicks
  • Has referred 50+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+6 more
PixelBin says

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. :)

374 posts
  • Has been part of the Envato Community for over 5 years
  • Has referred 1+ members
  • Has sold $1,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+3 more
_rohan says
<?php if ( have_posts() ) : while ( have_posts() ) : the_post();

$metaval= (get the meta);

if($metaval=="vid")
{
  (display post);
  break;
}

endwhile;endif;

?>

by
by
by
by
by
by