1475 posts The right tools with none of the gimmicks
  • Sold between 50 000 and 100 000 dollars
  • Elite Author
  • Has been a member for 4-5 years
  • Referred between 50 and 99 users
  • Bought between 10 and 49 items
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • United States
+1 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
  • Bought between 10 and 49 items
  • Contributed a Blog Post
  • Contributed a Tutorial to a Tuts+ Site
  • Exclusive Author
  • Has been a member for 4-5 years
  • Referred between 1 and 9 users
  • Sold between 1 000 and 5 000 dollars
_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