How to display custom post type ordered by a custom field date


I have a custom post type for a timeline activities.

each post of them has a custom field type of DATE. field name :activity-date

I’m using TYPES plugin for Custom Post Type and Custom Fields

I would like to order these posts by the custom date field, I tried the following but didn’t work.

<?php $activities = new WP_Query( array(
    'post_type' => 'timeline',
    'posts_per_page' => -1,
    'key'           => 'activity-date',
    'orderby'       => 'meta_value_num',
    'order'         => 'ASC'                            
)); ?>

enter image description here

, , , Murhaf Sousli 2 years 2020-01-15T08:41:15-05:00 0 Answers 82 views 0

Leave an answer