1

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

4
  • Please share the commands you have put together, so that others can review and give suggestions. – Q Studio Jan 16 at 9:14
  • I added it. So do you know how to use this to filter by post type? – pathfinder Jan 16 at 16:21
  • And for more info, I am doing multiple passes on the DB, one to remove the <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. – pathfinder Jan 16 at 16:31
  • 1
    Sounds like a feature request to me. Sounds also that this probably should be more of a post update command then. See the linked issue on GitHub, this may be done via wp db cli and then update wp_posts SET post_content = REPLACE(post_content, 'before', 'after') where post_type = 'page'; maybe. – leymannx Jan 17 at 22:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.