Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Henric Åkesson on "Query post if custom field is greater than"

$
0
0

Hi!

Im having a query like this:

<?php query_posts(array('category_name' => 'evenemang', 'posts_per_page' => '1', 'meta_key' => 'evenemangsdatum', 'orderby' => 'meta_value_num', 'order' => 'ASC')); while ( have_posts() ) : the_post(); ?>

And then I have a statement to decide if my "Event date" has been or not.

<?php $dateformatstring = "ymd";
$unixtimestamp = strtotime(get_field('evenemangsdatum'));
$evenemangsdatum = date_i18n($dateformatstring, $unixtimestamp); ?>

<?php $dagensdatum = date('ymd'); ?>

<?php if($evenemangsdatum >= $dagensdatum) { ?>

The problem is that I just want to query one post, and as you can see in my query i want to query the one that is closest to the "Event date". Only problem is if I have just one event that has not been, it still looking for old stuff because in the query it don't know that it should not query date that has been.

So what I want is to make this code: "if($evenemangsdatum >= $dagensdatum) {" get into the query in someway, or maybe posts_per_page to -1 and then just show the closest in some other way?


Viewing all articles
Browse latest Browse all 8245

Trending Articles