1479 posts The right tools with none of the gimmicks
  • Affiliate Level 4
  • Author Level 7
  • Beta Tester
  • Collector Level 2
+7 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
  • 6 Years of Membership
  • Affiliate Level 1
  • Author Level 3
  • Collector Level 2
+4 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