我正在尝试使用 WP_Query() 在我的 wordpress 博客上显示一些帖子。这个想法是在最近 30 天内发布的帖子中显示 9 个随机选择的帖子。由于某些原因,这似乎不起作用。
这是我使用的代码:
function filter_where_custom( $where = '' ) {
// posts in the last 30 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
return $where;
}
$args = "orderby=rand&posts_per_page=9";
$my_query = new WP_Query();
add_filter('posts_where', 'filter_where_custom');
$my_query->query($args);
我认为问题在于使用 add_filter 但到目前为止我一直无法理解我做错了什么。任何帮助都会很棒:)谢谢