admin管理员组文章数量:1026989
This question can be stupid but I really need a solution for it.. I am generating classified post using cron job. I have some custom filed as well with the cron job like 'source_link'. Sometimes that custom filed data may not be set for error or any kind of situation. So I want that post with empty data for custom field 'source_link' to be deleted automatically. Is this possible anyway ?
Here the code how I do I create post and set custom field data
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);
This question can be stupid but I really need a solution for it.. I am generating classified post using cron job. I have some custom filed as well with the cron job like 'source_link'. Sometimes that custom filed data may not be set for error or any kind of situation. So I want that post with empty data for custom field 'source_link' to be deleted automatically. Is this possible anyway ?
Here the code how I do I create post and set custom field data
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);Share Improve this question asked Mar 25, 2019 at 17:01 Tuhin A.Tuhin A. 1757 bronze badges
1 Answer
Reset to default 1 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;
}
}
This question can be stupid but I really need a solution for it.. I am generating classified post using cron job. I have some custom filed as well with the cron job like 'source_link'. Sometimes that custom filed data may not be set for error or any kind of situation. So I want that post with empty data for custom field 'source_link' to be deleted automatically. Is this possible anyway ?
Here the code how I do I create post and set custom field data
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);
This question can be stupid but I really need a solution for it.. I am generating classified post using cron job. I have some custom filed as well with the cron job like 'source_link'. Sometimes that custom filed data may not be set for error or any kind of situation. So I want that post with empty data for custom field 'source_link' to be deleted automatically. Is this possible anyway ?
Here the code how I do I create post and set custom field data
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);Share Improve this question asked Mar 25, 2019 at 17:01 Tuhin A.Tuhin A. 1757 bronze badges
1 Answer
Reset to default 1 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;
}
}
本文标签: functionsAuto delete post if certain custom field data is empty
版权声明:本文标题:functions - Auto delete post if certain custom field data is empty 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745659108a2161780.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论