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

Each of my posts have a single custom field that is a string of a date (not the date of the post). Instead of my theme's current query, which orders by published date, I want to order by this custom field date. How can I change this query (the theme's query) to instead use my custom field (a string representation of a date)?

$timeline_query = new WP_Query(array( 
    'post_type' => 'post', 
    'orderby' => 'date', 
    'order' => 'DESC', 
    'posts_per_page' => -1 
share|improve this question

The WP_Query page on the Codex has a section on Order & Orderby Parameters.

If you want to order the query by a custom field you should add 'orderby' => 'meta_value' AND you must also specify the custom field (called your_date_field in the above example) using the meta_key key in the query.

$timeline_query = new WP_Query(array( 
    'post_type' => 'post', 
    'orderby' => 'meta_value',
    'meta_key' => 'your_date_field' 
    'posts_per_page' => -1 
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.