这个问题可能很愚蠢,但我真的需要一个解决方案。。我正在使用cron作业生成分类帖子。我有一些自定义文件以及cron作业,如“source\\u link”。有时,自定义字段数据可能不会设置为错误或任何类型的情况。因此,我希望自动删除自定义字段“source\\u link”中包含空数据的帖子。这有可能吗?
下面是如何创建post和设置自定义字段数据的代码
kses_remove_filters();
$new_id = wp_insert_post($post_arr, true);
kses_init_filters();
if (is_wp_error($new_id)) {
$this->write_log("error occurred in wordpress post entry: " . $new_id->get_error_message() . " " . $new_id->get_error_code(), true);
return;
}
update_post_meta($new_id, \'source_link\', $url);
最合适的回答,由SO网友:Qaisar Feroz 整理而成
kses_remove_filters();
$new_id = wp_insert_post($post_arr, true);
kses_init_filters();
if (is_wp_error($new_id)) {
$this->write_log("error occurred in wordpress post entry: " . $new_id->get_error_message() . " " . $new_id->get_error_code(), true);
return;
}
if($url) update_post_meta($new_id, \'source_link\', $url);
else {
// wp_delete_post($new_id); // Move post to trash
$deleted = wp_delete_post($new_id, true); // Permanently delete post
if(! $deleted ){
$this->write_log("error deleting post entry.", true);
return;
}
}