There’s a terrible problem I had to work around for this content too — it used to be on a Classic Editor post.
When converting to the Block Editor, when clicking “Convert to Blocks” on the classic freeform block, it would totally mess up with the “code” shortcodes and think they were really shortcodes.
I had to run that same preg replace logic from my previously linked gist on ALL of the post content in the DB to try to fix that problem. Then it wasn’t enough, because the block editor / classic block kept converting those entities into the regular [
and ]
characters.
So nothing I did there worked until I ran this SQL on the content I had converted to entities already which would replace those entities with a temporary variable.
Here is the query I would run before loading the Block Editor for the post (remove space between & and #):
UPDATE wp_posts
SET post_content = REPLACE( REPLACE( post_content, '& #091;', '___BADSTART___' ), '& #093;', '___BADEND___' );
That let me run the “Convert to Blocks” and then it works! It converts the blocks correctly and the <pre>
tags all transform correctly! But now to fix those temporary vars…
Here is the query I would run after saving the post (remove space between & and #):
UPDATE wp_posts
SET post_content = REPLACE( REPLACE( post_content, '___BADSTART___', '& #091;' ), '___BADEND___', '& #093;' );
I sincerely hope whoever goes looking for this information finds it and it’s helpful to them. Please let this all be for the benefit of someone else other than me ??
Now I have 54 more posts to perform these steps on to convert them to the Block Editor…