Skip to content

Instantly share code, notes, and snippets.

@Kudratullah
Last active February 15, 2016 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kudratullah/93463c753377266c53cd to your computer and use it in GitHub Desktop.
Save Kudratullah/93463c753377266c53cd to your computer and use it in GitHub Desktop.
WordPress Post Date Query for this month's posts and previous month's posts
<?php
global $current_user;
$ThisMonthArgs = array(
'post_type' => 'post',
'author'=> $current_user->ID,
'posts_per_page' => -1,
'date_query' => array(
array(
'column' => 'post_modified_gmt',
'after' => array(
'year' => date('Y'),
'month' => date('m'),
'day' => 01,
),
),
array(
'column' => 'post_modified_gmt',
'before' => array(
'year' => date('Y'),
'month' => date('m'),
'day' => date('t'),
),
),
),
);
$LastMonthArgs = array(
'post_type' => 'post',
'author'=> $current_user->ID,
'posts_per_page' => -1,
'date_query' => array(
array(
'column' => 'post_modified_gmt',
'before' => array(
'year' => date('Y', strtotime('-1 Month')),
'month' => date('m', strtotime('-1 Month')),
'day' => date('t', strtotime('-1 Month')),
),
),
array(
'column' => 'post_modified_gmt',
'after' => array(
'year' => date('Y', strtotime('-1 Month')),
'month' => date('m', strtotime('-1 Month')),
'day' => 01
),
)
),
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment