Skip to content

Instantly share code, notes, and snippets.

@norcross
Created March 21, 2013 03:46
Show Gist options
  • Save norcross/5210538 to your computer and use it in GitHub Desktop.
Save norcross/5210538 to your computer and use it in GitHub Desktop.
manipulating the date info for WP_Query
<?php
// first get two related time settings
$zone = get_option('timezone_string');
$gmto = get_option('gmt_offset');
// is it a name based timezone selection? then create the offset
if (!empty($zone)) {
$zone = new DateTimeZone($zone);
$offs = $zone->getOffset(new DateTime);
$offs = $offs * -1;
// using old school UTC offset? fine then. be that way.
} else {
$offs = ( ($gmto * 3600) * -1 );
}
// get my server time
$now = time();
// calculate my offset
$stamp = ($now - $offs);
// get my integer values
$d = date('d', $stamp);
$m = date('m', $stamp);
$y = date('Y', $stamp);
$args = array(
'day' => $d,
'month' => $m,
'year' => $y
);
$posts = get_posts( $args );
print_r($posts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment