Instantly share code, notes, and snippets.

@raiden808 /count_post_by_month Secret
Last active Jun 13, 2018

Embed
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)');
?>
<select>
<?php
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>
<?
}
?>
</select>
<?php
}
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