0

Hello I have a custom post type event and i have two custom fields:

  1. event_date
  2. event_type

I want to display all my events which has event_type = Featured and sorting should be by event_date in DESC order..

I have searched everywhere on SOF but unable to find any working solution.. Here is my code right now

$events = new WP_Query(
                            array(
                                'post_type' => 'event',
                                'post_status' => 'publish',
                                'meta_key' => 'event_type',
                                'meta_value' => 'featured',
                                'posts_per_page' => -1,
                                'orderby' => 'event_date',
                                'order' => 'DESC'
                            )
                        );

screenshot enter image description here

2

Please change your args like this.

$meta_query = array(
    array(
        'key' => 'event_type',
        'value' => 'featured',
        'compare' => '='
    )
);

$args = array(
    'post_type' => 'event',
    'posts_per_page' => -1,
    'order' => 'DESC',
    'orderby' => 'meta_value_num',
    'meta_key' => 'event_date',
    'meta_query' => $meta_query
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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