我不能评论,因为我没有代表
您的代码不会更新,因为meta_key
字段不在wp_post
桌子
首先,您需要查询所有包含meta_键的帖子wpcf-engine-days-to-go
= 0 and then iterate through the post ID\'s and make your changes to the WP posts.
未测试示例:
$meta_value = 0;
$results = $wpdb->get_results("SELECT * from wp_posts, wp_postmeta
WHERE wp_posts.ID = wp_postmeta.post_id
AND wp_posts.post_status = \'publish\'
AND wp_postmeta.meta_key =\'wpcf-engine-days-to-go\'
AND wp_postmeta.meta_value = \'".$meta_value ."\'", ARRAY_A );
foreach($results as $row){
// do update on this POST
$update = $wpdb->update(\'wp_post\',
array(\'post_status\' => \'draft\'),
array(\'ID\' => $row[\'ID\'] ),
array(
\'%s\', // string
),
array( \'%d\') // id
);
}
}