[英]MySQL query to get data in WordPress Php base on numbers of exact days from Current
i want to get the ID from the post table where the post_modified date is exactly 5day ago. 我想从发布表中获取ID,其中post_modified日期恰好是5天前。 and foreach ID i get i will do another call another function.
我得到的foreach ID我将再次调用另一个函数。 i know i have to add a loop somewhere but mybrains hurts when it comes to looping please help!
我知道我必须在某处添加一个循环,但是在循环时mybrains会受伤,请帮忙!
i have 3 example records to compare date. 我有3个示例记录来比较日期。
{
status: "ok",
post: [
{
ID: "99",
post_modified: "2015-09-02 07:58:14"
},
{
ID: "100",
post_modified: "2015-09-04 02:59:27"
},
{
ID: "101",
post_modified: "2015-09-09 07:36:56"
}
]
}
this is myfunction code 这是我的功能代码
public function test(){
global $wpdb;
$data= $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status like 'wc-completed' AND post_modified < DATE_SUB(now(), INTERVAL 5 DAY)");
return $data;
}
好吧,我解决了该问题,以便每隔5天获取正确的数据库
$data= $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status like 'wc-completed' AND DATE_SUB(CURDATE(),INTERVAL 5 DAY) <= post_modified");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.