admin管理员组文章数量:1124750
The goal is to show today's published posts or, if there's none, the last day's with posts published posts.
I found this old question, but the code suggested uses query_posts
. I'd like to use WP_Query
. I tried to scramble something, but it didn't work:
$current_year = date('Y');
$current_month = date('m');
$current_day=date('d');
$today = getdate();
$last_date = $wpdb->get_var("SELECT DATE(MAX(post_date)) FROM {$wpdb->posts} LIMIT 1");
if (!empty($last_date)) {
list($current_year,$current_month,$current_day) = explode('-',$last_date);
}
$args = array(
'date_query' => array(
array(
'after' => array(
'year' => $today["year"],
'month' => $today["month"],
'day' => $last_date,
),
'inclusive' => true,
),
),
'posts_per_page' => -1,
);
Any idea what's wrong?
本文标签: wp queryHow to display only posts from the last day with posts published
版权声明:本文标题:wp query - How to display only posts from the last day with posts published? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736646706a1946124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论