When trashing a post, also trash related comments so here is what i want, what‘s’ the sql Command
I want to move some post to trash according their ID, what is the sql command,I can restore these post and their comments using sql command
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI would discourage using raw SQL for moving a post to a trash or back, especially since there's a build in function for it:
wp_trash_post( $post_id );
More about the wp_trash_post() function.
The opposite is:
wp_untrash_post( $post_id );
wp_untrash_post()
also untrashes trashed comments.
In WP there are functions for many things - for instance you can trash/untrash only comments, leaving the post alone - in that case use: wp_untrash_post_comments()
and wp_trash_post_comments()
.
Sql Command for trashed a post with comments for that post:
$post_status = 'trash';
$post_array = '1, 2, 3'; //post_ids comma separated
$wpdb->query($wpdb->prepare(
"UPDATE
`wp_posts`,
`wp_comments`
SET
wp_posts.post_status= %s,
wp_comments.comment_approved= %s
WHERE
wp_posts.ID = wp_comments.comment_post_ID AND
wp_posts.ID IN ( $post_array )",
$post_status,
$post_status
));