全投稿に対して何か処理をする。
<?php ini_set('max_execution_time',180); require_once('wp-load.php'); require_once('wp-config.php'); $results = $wpdb->get_results("SELECT ID FROM $wpdb->posts"); foreach ($results as $value) { $post_ID = $value->ID; $post = get_post($post_ID); (何か処理) // wipe post from memory wp_cache_delete($post->ID, 'posts'); wp_cache_delete($post->ID, 'post_meta'); }
wp_cache_delete しないと Allowed memory size of ... のエラーになる。
参考
WordPressで特定のカテゴリのアイキャッチを全て削除するバッチ処理 - よっぽどのことがない限り更新しないブログ
https://wordpress.stackexchange.com/questions/71687/loop-through-all-posts-memory-error
WordPressからデータベースに直接アクセスする | webOpixel