Formatting a date/time returned from a custom $wpdb query

A much simpler method to bypass these issues is using WP_Query: $popularQuery = array(‘orderby’ => ‘comment_count’, ‘posts_per_page’ => ‘-1’, ‘author’ => 1); $popularPosts = new WP_Query($popularQuery); while($popularPosts->have_posts()) : $popularPosts->the_post(); ?> <tr> <td><a href=”https://wordpress.stackexchange.com/questions/23820/<?php the_permalink(); ?>”><?php the_title(); ?></a></td> <td><?php the_author(); ?></td> <td><?php the_time(‘j M Y h:i A’) ?></td> <td><?php comments_number(); ?></td> </tr> <?php endwhile; Also note … Read more

Order by custom date field

I found the following solution: SELECT wposts . * FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = ‘datum’ AND wposts.post_type=”optredens” AND wposts.post_status=”publish” ORDER BY wpostmeta.meta_value ASC As other query_posts() methods / alternatives did not work very well.

How to query posts by month based on date custom field?

It is not clear what you’re using as a comparison, but WP Query supports meta query comparisons and even has a DATE type. For example: $query = new WP_Query( array( ‘post_type’ => ‘attraction’, ‘meta_key’ => ‘attraction_date’, ‘meta_value’ => ’10’, ‘meta_compare’ => ‘LIKE’, ‘type’ => ‘DATE’ ) ); Using 10 is not going to get you … Read more