我有一个cron作业集,可以从数据库中删除(有时是大量)帖子。当然,我还需要删除所有相关数据,例如自定义字段。
这是我当前正在运行的函数,但删除所有内容需要一些时间。
直接进行SQL查询是否更有效?
/**
* Delete all items
*
*/
function myplugin_delete_all_items() {
$args = array(
\'post_type\' => \'my_post_type\',
\'posts_per_page\' => -1,
);
$items = new WP_Query( $args );
if ( $items->have_posts() ) :
while ( $items->have_posts() ) : $items->the_post();
$postid = get_the_ID();
$purge = wp_delete_post( $postid, true );
endwhile;
endif;
wp_reset_postdata();
}