使用“fields”=>“ids”参数时,在下面的代码中创建新的WP\\u查询是否比执行get\\u post更好?
如果使用WP\\u查询,循环会是什么样子?
function myplugin_delete_image_items( $postid ) {
$args = array(
\'post_type\' => \'myplugin_image_item\',
\'cache_results\' => false, // Disable caching, used for one-off queries
\'no_found_rows\' => true, // We don\'t need pagination, so disable it
\'fields\' => \'ids\', // Returns post IDs only
\'meta_query\' => array(
array(
\'key\' => \'myplugin_image_id\',
\'value\' => $postid,
\'compare\' => \'LIKE\'
)
)
);
$image_item_ids = get_posts( $args );
foreach( $image_item_ids as $image_item_id ) {
$purge = wp_delete_post( $image_item_id, true ); // delete the image item, skipping trash
}
wp_reset_postdata();
}