Skip to content

Instantly share code, notes, and snippets.

@raiden808 raiden808/count_post_by_month Secret
Last active Jun 13, 2018

What would you like to do?
function count_post_by_month_callback(){
global $wpdb;
$prefix = $wpdb->prefix;
$months = $wpdb->get_results( 'SELECT meta_value,COUNT("post_id") as month_total FROM '.$prefix.'postmeta WHERE `meta_key` = "departure_date" GROUP BY MONTH(meta_value)');
foreach ($months as $month) {
//This will only show the Month and Year
$date = date('F Y', strtotime($month->meta_value));
<option value="<?php echo $date; ?>" ><?php echo $date." (".$month_total.")"; ?></option>
add_shortcode( 'count_post_by_month', 'count_post_by_month_callback' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.