WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've found several similar question but none of them explains why the below is giving me nothing with ASC order. It works with DESC.

Basically it's a query that should list posts where the custom field values are equal or greater to the current date, then arrange it in reversed order, so the first post should be a post that's custom field are the closest the the current date.

<?php query_posts($query_string . '&showposts=4&order=ASC&post_type=custompost&meta_key=mydate&orderby=meta_value'); ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

        <?php $todays_date = date("Y/m/j"); ?>
        <?php $today = strtotime($todays_date); ?>
        <?php $exp_date = get_post_meta('mydate'); ?>
        <?php $expiration_date = strtotime($exp_date); ?>
        <?php if ($expiration_date >= $today) { ?>

            <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>

    <?php } else { ?>
    <?php };?>

<?php endwhile; ?>
<?php else : ?>
<?php endif; ?> 

Also, I've tried many different queries but none of them worked, the above script is the latest I have.

share|improve this question
up vote 2 down vote accepted

With some more googling:

$today = date("Y/m/j");
'post_type' => 'custompost',
'posts_per_page' => 4,
'meta_key' => 'mydate',
'orderby' => 'meta_value',
'order' => 'ASC',
    'meta_query' => array(
           'key' => 'mydate',
           'meta-value' => $value,
           'value' => $today,
           'compare' => '>=',
           'type' => 'CHAR'
if (have_posts()) :
while (have_posts()) : the_post();
    <a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>

<?php endwhile; ?>
<?php else : ?>
<?php endif; ?> 

I hope it will help others!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.