I am trying to use WP-CLI to do a search and replace on about 10,000 posts that were imported from another CMS and it has a great deal of old inline styles and spans and such. I would like to be able to use the search and replace function to remove a lot of chaff using regex. I have no issue creating the regex or limiting my command to just the content column in the wp_posts table, but I do not see a built in way way to limit my post_type
to only post
, not page
or others that are in the wp_posts
table. Is there one?
Here is a code example:
wp search-replace '<span^.*>' '' --regex wp_posts --include-columns=post_content
<span>
and another to remove the</span>
, likely I will end up writing a php script that handles the post type filter and run my wp-cli command entry by entry in a loop if there is no way to filter the post type as part of my command line command.post update
command then. See the linked issue on GitHub, this may be done viawp db cli
and thenupdate wp_posts SET post_content = REPLACE(post_content, 'before', 'after') where post_type = 'page';
maybe.