admin管理员组文章数量:1122832
I have an author named News Agencies and it has 50000 WordPress post from 5 months, I need to delete news agencies post from this specific author of 3 months only. Is there any SQLI command to do this task?
Specific author >> from December to march
I have an author named News Agencies and it has 50000 WordPress post from 5 months, I need to delete news agencies post from this specific author of 3 months only. Is there any SQLI command to do this task?
Specific author >> from December to march
Share Improve this question asked May 1, 2024 at 16:13 C I WingC I Wing 11 Answer
Reset to default 1Deleting posts directly in the DB is not going to clear up all their comments, post metadata, etc. I'd recommend using wp_delete_post()
to do this instead.
// Gets the post IDs.
$author_id = get_user_by( 'login', 'newsagencies' ); // Use the user's login here.
$posts = new WP_Query(
array(
'author' => $author_id,
'date_query' => array(
'after' => '2023-12-01',
'before' => '2024-03-31',
),
'fields' => 'ids',
'posts_per_page' => -1, // Get *all* the posts.
),
);
$force_delete = true; // Set this to 'false' if you only want to trash
// the posts, not actually delete them permanently.
if ( ! empty( $posts->posts ) ) {
foreach ( $posts->posts as $post_id ) {
wp_delete_post( $post_id, $force_delete );
}
}
Notes
- With 50,000 posts, this might take a while.
- This code is meant as a starting point only; it's not production-ready, and should be tested on a test site first.
References
WP_Query
classget_user_by()
wp_delete_post()
本文标签: wp querySQL command to delete bulk WP post specific
版权声明:本文标题:wp query - SQL command to delete bulk WP post specific 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308626a1933730.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论