Show Posts From last 30 days

To get the post from last 30 days or 1 month old, put the following hook before query begin as following:

add_filter('posts_where', 'filter_where_one_month');

and put the following function on functions.php file

<?php
//get post from 1 month old 
function filter_where_one_month( $where = '' ) {
	//posts in the last 30 days
	$where .= " AND post_date >= '" . date('Y-m-d', strtotime('-30 days')) . "'";
	return $where;
}
?>

Comments

comments

Leave a Reply