Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get posts that is between today and last month? Wordpress Issue [closed]

For example, today is 25 January 2016, i want to get the posts that are published between TODAY with year 2015, month December, day 25.

It seems simple, but there are issues where the month ends with 30,31, 28, etc. Not to mention i have to manually count whether it is January (because if it's january, i have to reduce the year by 1, current_year - 1).

Anyone have a good solution for the WP_Query to achieve this?

like image 639
Raymond Seger Avatar asked Dec 19 '22 20:12

Raymond Seger


1 Answers

WP_Query(https://codex.wordpress.org/Class_Reference/WP_Query) allows you use time shifting in format of php-function strtotime(). Ex:

$args = array(
  'date_query' => array(
    array(
      'after'   => '-1 month',
    ),
  ),
);
$query = new WP_Query( $args );
like image 100
patlach Avatar answered Jan 26 '23 00:01

patlach