我试图在X天后删除WordPress帖子。 我正在使用此代码。
$daystogo = 30;
$sql =
"UPDATE {$wpdb->posts}
SET post_status = 'trash'
WHERE (post_type = 'post' AND post_status = 'publish')
AND DATEDIFF(NOW(), post_date) > %d";
$wpdb->query($wpdb->prepare( $sql, $daystogo ));
但我想在元键上排除一些帖子。 就像我不想删除那个有FEATURD POST VALUE IS 1的帖子
'meta_query' => array(
array(
'key' => 'featured_post',
'value' => '1',
'compare' => '=='
)
),
任何在查询中添加此条件的方法?? 感谢
答案 0 :(得分:1)
这是你的mysql代码,你可以使用MySQL“IN()”函数:
$sql =
"UPDATE {$wpdb->posts}
SET post_status = 'trash'
WHERE (post_type = 'post' AND post_status = 'publish')
AND ID not in (select post_id from {$wpdb->postmeta} where
meta_key='featured_post' and meta_value='1' )
AND DATEDIFF(NOW(), post_date) > %d";