Skip to content

Instantly share code, notes, and snippets.

@maor
Created October 26, 2012 13:39
Show Gist options
  • Save maor/3958879 to your computer and use it in GitHub Desktop.
Save maor/3958879 to your computer and use it in GitHub Desktop.
How WP queries date-based archives
if ( $q['m'] ) {
$q['m'] = '' . preg_replace('|[^0-9]|', '', $q['m']);
$where .= " AND YEAR($wpdb->posts.post_date)=" . substr($q['m'], 0, 4);
if ( strlen($q['m']) > 5 )
$where .= " AND MONTH($wpdb->posts.post_date)=" . substr($q['m'], 4, 2);
if ( strlen($q['m']) > 7 )
$where .= " AND DAYOFMONTH($wpdb->posts.post_date)=" . substr($q['m'], 6, 2);
if ( strlen($q['m']) > 9 )
$where .= " AND HOUR($wpdb->posts.post_date)=" . substr($q['m'], 8, 2);
if ( strlen($q['m']) > 11 )
$where .= " AND MINUTE($wpdb->posts.post_date)=" . substr($q['m'], 10, 2);
if ( strlen($q['m']) > 13 )
$where .= " AND SECOND($wpdb->posts.post_date)=" . substr($q['m'], 12, 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment