Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7070431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:33:56+00:00 2026-05-28T05:33:56+00:00

How do I order post by a custom field if releasedate > currentdate but

  • 0

How do I order post by a custom field if “releasedate” > “currentdate” but in acending order. Basically only display post with dates starting after today but in ascending order. currently i have

<?php 
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('showposts=10&post_type=movies&meta_key=releasedate_value&orderby=releasedate_value&order=ASC');
if (have_posts()) : while (have_posts()) : the_post(); 
$currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
?>


<?php if ($releasedate >  $currentdate) {?>

“my contents/ post here”

<?php } ?>
<?php endwhile; ?>
<?php endif; ?>

now everything works except when its ASC and not DSC, no post will display because wordpress in getting the post first and the erasing the post that are not before current date and only 10 post are allowed, therefore if 10 post has a release date before today, wordpress loads then erase them after and leaves everything blank! Thank you for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T05:33:57+00:00Added an answer on May 28, 2026 at 5:33 am

    I’d put the date criteria into the query itself. Assuming you have WordPress version 3.1 or higher, you can use the meta_query parameter. Something like:

    <?php
    $currentdate = date("Y-m-d",mktime(0,0,0,date("m"),date("d"),date("Y")));
    
    $wp_query = new WP_Query(  array ('showposts' => 10,
                    'post_type' => 'movies',
                    'meta_query'=> array(
                        array(
                          'key' => 'releasedate_value',
                          'compare' => '>',
                          'value' => $currentdate,
                          'type' => 'DATE',
                        )),
                    'meta_key' => 'releasedate_value',
                    'orderby' => 'meta_value',
                    'order' => 'ASC'
        )
    );
    

    should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom field name front_sl_slider. I want to display all the posts
I am trying to display results of a custom post type on my main
I want to know something about this article In order to create custom post
Why is it necessary to keep visited flag for iterative post order traversal and
say I have this $result = mysql_query('SELECT views FROM post ORDER BY views ASC');
In handling a form post I have something like public ActionResult Insert() { Order
Is the order, or sequence, of rules in CSS significant? This post says that
I have many Topic objects and each Topic hasMany posts:Post How can I order
I am wondering if I could use simply use HTTP POST Requests in order
After seeing a previous post Making Applications programmed in .NET languages work on older

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.