Last active
December 1, 2015 11:12
-
-
Save Plou/b973618735fe4cbc33cc to your computer and use it in GitHub Desktop.
Get month and years from list of custom post in wp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$yearsStart = $wpdb->get_col("SELECT YEAR(FROM_UNIXTIME((meta_value / 1000))) FROM wp_postmeta WHERE meta_key LIKE 'start_date' ORDER BY meta_value ASC"); | |
$yearsEnd = $wpdb->get_col("SELECT YEAR(FROM_UNIXTIME((meta_value / 1000))) FROM wp_postmeta WHERE meta_key LIKE 'end_date' ORDER BY meta_value ASC"); | |
$tempyears = array_unique(array_merge($yearsStart, $yearsEnd)); | |
$currentYear = date('Y'); | |
$currentMonth = date('m'); | |
foreach (array_unique($yearsStart) as $year) { | |
if($year >= $currentYear) { | |
$tempMonths = $wpdb->get_col("SELECT DISTINCT MONTH(FROM_UNIXTIME((meta_value / 1000))) FROM wp_postmeta WHERE meta_key LIKE 'start_date' AND YEAR(FROM_UNIXTIME((meta_value / 1000))) = $year ORDER BY meta_value ASC"); | |
foreach ($tempMonths as $month) { | |
if($year > $currentYear OR $month >= $currentMonth) { | |
$months[] = $month; | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment