Reputation: 586
Here I am changing status of my Published posts to draft where post have less content using following code
function draftpost(){
global $wpdb;
$prefix = $wpdb->prefix;
$wpdb->query("UPDATE ".$prefix."posts SET post_status='draft' WHERE LENGTH( post_content ) <500");
}
add_action('publish_post', 'draftpost');
This code is working Fine for changing Published Items to Draft.
Issue is that this code removes my Custom Menu and make all Items in Menu to PENDING. How can I solve this?
Upvotes: 1
Views: 1298
Reputation: 76
You need to extend your query.
$wpdb->query("UPDATE ".$prefix."posts SET post_status='draft' WHERE LENGTH( post_content ) < 500 AND post_type = 'post'");
Your query overwrites all post_types, including nav_menu_item.
Upvotes: 3