Sort custom post type by custom field not working
-
Hi there,
I am trying to display my custom post type ‘events’ in event date ascending order but am having no luck! I am also only displaying events if they are in the future. I believe I have followed instructions on how to order by custom post type correctly –
// Get the current date $current_date = date('M d, Y', time() - 86400); $current_date = strtotime( $current_date ); $args = array( 'post_type' => 'events', 'meta_key' => 'event_date', 'orderby' => 'meta_value_num', 'order' => ‘ASC’ ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); // Get the custom field $post_date = get_field('event_date'); $post_date = strtotime( $post_date ); // If older than current date, don't show it if( $post_date > $current_date ): ?> <article class="event">MY POST STUFF</article> <?php endif; /* END DATE FILTER */ endwhile; // END LOOP ?>
Has anyone got any suggestions?
Thanks
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Sort custom post type by custom field not working’ is closed to new replies.