How Do I Bulk Update Articles Using Search and Replace in Content and Titles?

How Do I Bulk Update Articles Using Search and Replace in Content and Titles?

How Do I Bulk Update Articles Using Search and Replace in Content and Titles?

Note: These actions must be performed by a developer with permission to run commands on our daemon server. This article can be referenced in JIRA tickets as needed.

How to Use Regex Search and Replace in Article Content

You can use the WordPress CLI to perform a search-and-replace operation across your content. For example, to update URLs or other text in your articles, use the following command:

wp search-replace --url=d%account_id%.cms.socastsrm.com 'jpbgimages.cachefly.net' 'cloudinary.jpbgdigital.com' wp_%blog_id%_postmeta --regex --regex-flags='i'

For more details, refer to the WordPress Search Replace documentation.

Note: You can target specific WordPress tables that need to be updated. For example, thumbnail URLs are stored in the wp_postmeta table.

WordPress CLI Example

If you are satisfied with the dry run, you can run the command without the --dry-run flag to apply the changes.

WordPress CLI Output

How to Update SoCast Elastic Cache

News widgets use data cached in Elasticsearch. After updating the database, you must refresh the data in Elasticsearch. Run the following command:

wp socast-elasticsearch index_create --check_exists=false --url=d%accountID%.cms.socastsrm.com

How to Perform Bulk Updates Across Multiple Sites (Multisite)

If you need to perform the same operation on multiple sites, create a bash script containing all necessary commands. Use and update the provided sample file as needed.

Upload the script to the /socast folder on the daemon server and run the following command:

nohup ./SP14331.sh > SP14331_report.txt

You can close your terminal if needed. Use the generated report file to monitor the progress of the script until all actions are completed.