【发布时间】:2016-01-15 02:30:11
【问题描述】:
我想过滤 WP_Query 以检索所有 woocommerce 订单(post_type = shop_order) 具有超过 15 分钟的特定状态。
即上次修改的所有帖子(现在 - 15 分钟)//希望我很清楚。
低于我的尝试
function filter_where($where = '') {
//posts in the last 15 minutes
$where .= " AND post_modified > '" . date('Y-m-d', strtotime('INTERVAL 15 MINUTE')) . "'";
return $where;
}
add_filter('posts_where', 'filter_where');
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish',
'posts_per_page' => 10,
'tax_query' => array(
array(
'taxonomy' => 'shop_order_status',
'field' => 'slug',
'terms' => array('completed')
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$order_id = $loop->post->ID;
$order = new WC_Order($order_id);
print_r("<pre>");
print_r($order);
print_r("</pre>");
endwhile;
但是返回所有记录,似乎必须修改 $where 查询,我该如何实现?
【问题讨论】:
-
你能告诉我们你在哪里声明
$loop吗? -
已更新,就在 while 循环上方