Skip to content

How to find all WordPress posts using a block

Last weekend I scrapped a WordPress block plugin that I wrote a few months ago and totally started over. They weren’t compatible and I stupidly used the same name. So now I had a site using the old version of the block that I couldn’t really upgrade to the new version without fixing old pages.

Fair enough, easy to do. I just needed to figure out what posts were using the old version of the block.

Found a pretty easy way using WP-CLI.

wp db query 'select id, post_title, post_status from wp_posts where post_content like "%the/block_id%" AND post_status!="inherit"'

Run that from the command line and swap out the/block_id with the actual block id and you’ll get a list of all posts that contain that block. I did include post_status!="inherit" so that revisions weren’t included.

Published inCodingWordPress

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *