Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This question already has an answer here:

i have a little problem: I can not order my events as i wish. I would like to order my upcoming events in ascending order...

I am using the following:

new WP_Query(
         array(
     'author' => $current_user->ID, 
     'post_type' =>'tribe_events', 
     'orderby' => 'meta_value', 
     'meta_key' => '_EventStartDate', 
      array(
           'key' => '_EventStartDate', 
           'value' => date('Y-m-d'), 
           'compare' => '>='
       )))

But nothing happens... i mean they don't get sort in any way.. I think this is because of the _EventStartDate witch includes an hour and it looks something like this if i echo it "2013-07-29 20:00:00". Any suggestions?

updates of the code :

global $current_user;
    get_currentuserinfo();
    $author_posts = new WP_Query(
 array(
    'author' => $current_user->ID, 
    'post_type' =>'tribe_events', 
    'orderby' => 'meta_value',
    'order' => 'DESC',
    'meta_key' => '_EventStartDate', 
     array(
          'key' => '_EventStartDate', 
          'value' => date('Y-m-d'), 
          'compare' => '>='
      )));
    while($author_posts->have_posts()) : $author_posts->the_post();

and here i just get the content...

share|improve this question

marked as duplicate by toscho Jul 2 '13 at 17:09

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

Format of this meta is OK - it should work. I'm not sure what you're doing in this query args, though. You use meta query incorrectly.

If you do it like this, it should work fine:

$my_query = new WP_Query(
    array(
        'author' => $current_user->ID, 
        'post_type' => 'tribe_events', 
        'orderby' => 'meta_value',
        'order' => 'ASC',
        'meta_key' => '_EventStartDate', 
        'meta_query' => array(
            array(
                'key' => '_EventStartDate', 
                'value' => date('Y-m-d') . ' 00:00:00', 
                'compare' => '>='
            )
        )
    ));
share|improve this answer
new WP_Query(
     array(
 'author' => $current_user->ID, 
 'post_type' =>'tribe_events', 
 'orderby' => 'meta_value',
 'order' => 'DESC',
 'meta_key' => '_EventStartDate', 
  array(
       'key' => '_EventStartDate', 
       'value' => date('Y-m-d'), 
       'compare' => '>='
   )))

Yeah, Like Krzysiek Drozdz said, it should work, don't forget to add this one * order => DESC or ASC. WordPress Query Post can make anything orders even title. Just suggest for your answers!

share|improve this answer
    
You're doing the same mistake - what is that array "floating" without key in your args? –  Krzysiek Dróżdż Jul 2 '13 at 12:09
    
i've made an update on the code –  emcee22 Jul 2 '13 at 12:14
    
I'm not sure what have you changed, but the array (I assume you wanted to do meta_query) is still incorrect. –  Krzysiek Dróżdż Jul 2 '13 at 12:16
    
Yea, still wrong, look at @KrzysiekDróżdż answer for the correct way and your answer offers absolutely no additional information. –  ialocin Jul 2 '13 at 12:19
    
ok sorry, i've changed my code... same result :( i guess it is something else.. but what could it be .. on this page i only got the loop and thats it.. –  emcee22 Jul 2 '13 at 12:24

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