$post_ids = get_posts(array(
'posts_per_page'=> -1,
'fields' => 'ids',
));
[参考] https://elearn.jp/wpman/function/query_posts.html 上記のコードで取得可能。
全件:’posts_per_page’=> -1
idのみを取得:’fields’ => ‘ids’
あとはこれをforloopの中で回すことによりid毎の処理が実行可能


