Firstly, I would consider using one of WordPress’ wp_kses
-like functions, instead of PHP’s strip_tags()
.
Secondly, query your posts with WP_Query
or get_posts()
with the fields
parameter set to ids
– seems like you don’t need more than that.
Thirdly, split up your loop into steps that are effective and manageable. Because 34000+ posts will likely reach the limits of your server – at the very least regarding processing time.
You could for example make smart use of the posts_per_page
and/or offset
parameters for WP_Query
/get_posts
. Or you might do it by handling the complete array of IDs you can get by setting posts_per_page
to -1
another way with PHP. For an exemplary approach take a look at the following answer by @TheDeadMedic on a similar matter.