How to sort custom post type by custom date field?
-
After searching around rather extensively, I cannot find a solution and this is beyond my WP expertise to write myself:
I have figured out how to get my output to sort by my custom field, but it is not sorting it “correctly”; it is currently sorting numerically by what is before the first “/”, and I need it to sort by the whole date. The date is in the format MM/DD/YYYY (but if the month is a single digit, it’s M/DD/YYYY), and currently it is only sorting by the month.
Basically, my sort isn’t ordering things correctly, and I need to get it to sort by the date (not numerically).
Here’s my loop and query:
<?php $loop = new WP_Query( array( 'post_type' => 'churchmedia', 'posts_per_page' => '200', 'meta_key'=>'date', 'orderby'=>'meta_value', 'order'=>'ASC',) ); while ( $loop->have_posts() ) : $loop->the_post(); ?> <?php $custom = get_post_custom($post->ID); $series = "". $custom["series"][0]; $speaker = "". $custom["speaker"][0]; $date = "". $custom["date"][0]; $video = "". $custom["video"][0]; $audio = "". $custom["audio"][0]; $notes = "". $custom["notes"][0]; ?>
Any help is greatly appreciated! This is driving me crazy.
- The topic ‘How to sort custom post type by custom date field?’ is closed to new replies.