Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #6307
    asileweb
    Participant

    Greetings,

    I am trying to get events with get_posts function and order the result by _event_start_Date “meta_key” with no success, what may I be doing wrong here ?

    Thank you

    function get_events_projet($post_id) {
      $args = array(
        'posts_per_page'   => -1,
        'meta_query' => array(
          array(
            'key' => '_ti_event_projet_link',
            'value' => $post_id,
            )
          ),
        'meta_key'   => '_event_start_date',
        'orderby' => 'meta_value_num',
        'order' => 'ASC',
        'post_type'        => 'event',
        'suppress_filters' => false 
        );
    
      $events_array = get_posts($args);
    
      return $events_array;
    
    }
    #6326
    Bartosz
    Keymaster

    To get events sorted in specific order you need to set it like that:

    
    'orderby' => 'event_start_date' // or event_end_date

    You don’t have to provide ‘_event_start_date’ meta_key or anything else event related but of course you can use any additional meta query parameters you need (like _ti_event_projet_link)

    #6329
    asileweb
    Participant

    Thank you for your reply, I guess I did not notice this in your documentation.
    Have a great day.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.