WP change request for output of records for the last 30 days
Current request:
$popular_posts = get_posts("cat=-104&orderby=comment_count");
It is necessary to withdraw for the last 30 days.
What should I change in the request?
I understand that you need to add &
and you can use the date, for example, for this month to output:
$popular_posts = get_posts('cat=-104&orderby=comment_count&year=' . $year . '&monthnum=' . $month);
after marking it:
$month = date('m');
$year = date('Y');
But how to play with the days in the query? So that the output is for the last 30 days in get_posts. That is, how to pass it through the parameter date_query
1
Author: theblackpost, 2018-10-01
2 answers
The code is
$args = array(
'category' => - 104,
'orderby' => 'comment_count',
'date_query' => array(
array(
'after' => '30 days ago',
),
),
);
$popular_posts = get_posts( $args );
2
Author: KAGG Design, 2018-10-01 11:08:18
And you can still do it like this:
$args = array(
'category' => -104,
'posts_per_page' => 5,
'post_type' => 'post',
'orderby' => 'comment_count',
'order' => 'DESC',
'date_query' => array(
'after' => date('Y-m-d', strtotime('-10 days'))
)
);
$posts = popular_posts ($args);
0
Author: theblackpost, 2018-10-04 12:38:47