PMC Plugins
Pmc Wp CLI

PMC WP CLI


Recently added commands

  • Most commands default to dry run to prevent accidental deletions. Make sure to use appropriate dry-run flag to run the actual command.
  • Most commands support max-iterations as an optional parameter. This is the number of rows to process per iteration. Default is 20.
  • The logs for the commands can be saved to your local system via the tee command. Example: wp pmc-meta update-meta --csv=file.csv --meta-key=noindex-post --meta-value='on' --dry-run=false | tee /local/path/to/log/file.log

Delete Legacy Redirects

This command is used to delete the legacy redirects from the legacy redirects table. It accepts a CSV file with a list of paths each on new line to delete from the legacy redirects table.

Required parameters: csv-file - Path to the CSV file

Note: Make sure to add a trailing slash to the path in the CSV file as legacy redirect plugins adds a trailing slash to the path and stores it as a md5 hash.

wp legacy-redirect-manager delete-redirects --csv-file=/path/to/file.csv --dry-run=false

Update meta data for posts

This command is used to update meta data for particular post Ids. All the posts will be updated with the set of key and value provided in the parameters. It accepts a CSV file with a list of post ids each on a new line. The meta data can be provided as a parameter.

Note: Accepts only single meta key and meta value to update.

Required parameters: csv-file - Path to the CSV file meta-key - Meta key to update meta-value - Meta value to update

wp pmc-meta update-meta  --csv=file.csv --meta-key=noindex-post --meta-value='on' --dry-run=false

Update meta data for terms

This Command is used to update meta data for the terms. It accepts a CSV file with a list of term ids on new line. The meta data can be provided as a parameter.

Note: Accepts only one meta key and meta value to update.

Required parameters: csv-file - Path to the CSV file meta-key - Meta key to update meta-value - Meta value to update taxonomy - Taxonomy to update term for

wp pmc-meta update-term-meta  --csv=file.csv --meta-key=noindex-post --meta-value='on' --taxonomy=category --dry-run=false

Update Internal http links

This CLI command updates internal http links to https and also adds a trailing slash to the path. This Script will run for all posts of that provided post types.

Important Parameters: post-type - Post type to update links for. Default is post. Accepts one post type at a time. dry-run - Default is true. Set to false to run the command.

wp pmc-http-cleanup update-http-internal-links --post-type=post --dry-run=false

Update post slug

The CLI command identifies posts having duplicate post_name (slug) and triggers save_post() to update its slug.

For some brands, multiple posts were saved with the same slug while migrating from old website which confuses the default WordPress' redirect engine and redirects URL incorrectly due to multiple posts having the same 'slug'. Ex: More than 150 Ask Billboard posts on BillBoard saved with ask-billboard slug.

wp pmc-post update_post_slug --dry-run=false

Retrieve a list of posts without authors.

This CLI command retrieves a list of posts without authors.

Important Parameters: post-types - Default is post. Set to any post type to retrieve posts without authors for that post type. post-status - Default is any. Set to any post status to retrieve posts without authors for that post status.

wp pmc-post get_posts_with_no_author --post-types=post --dry-run=false

Update/Remove URLs in post content.

This CLI command updates or removes URLs in post content.

Update URLs in the post content based on the CSV input and post id as an identifier for the post. If the to-replace URL is empty the Hyperlink will be removed and replaced with link label.

Please go through the command documentation for more details about the CSV format and URL structure.

** Note: ** This command will not be applicable for Lists and Galleries and they have a different structure.

Data Separators: ;

Required parameters: csv-file - Path to the CSV file

Important Parameters: provided-full-replace-urls - Default is false. Set to true if the CSV file contains the full URL to replace. offset - Default is 0. Set to the row number to start processing from if the command fails in between.

wp pmc-post-content update-urls --csv-file=file.csv --provided-full-replace-urls=true --dry-run=false

Update/Remove URLs in Galleries and Lists.

This CLI command updates or removes URLs in Galleries and Lists.

Update URLs in the Galleries and Lists based on the CSV input and post id as an identifier for the post. If the to-replace URL is empty the Hyperlink will be removed and replaced with link label.

Please go through the command documentation for more details about the CSV format and URL structure.

Data Separator: ;

Required parameters: csv-file - Path to the CSV file

Important Parameters: provided-full-replace-urls - Default is false. Set to true if the CSV file contains the full URL to replace. offset - Default is 0. Set to the row number to start processing from if the command fails in between.

wp pmc-post-content update-gallery-and-list-item-urls --csv-file=file.csv --provided-full-replace-urls=true --dry-run=false

Fix Slugs for posts

This CLI command fixes the slugs for posts based on the CSV input and post id or url as an identifier for the post.

It fixes the slugs for posts with the following conditions:

  • Invalid characters in the slug
  • Capital letters in the slug

Each ID or URL goes on a new line in the CSV file.

Required parameters: csv-file - Path to the CSV file with post id or url.

Important Parameters: post-field - Default is id. Set to url if the CSV file contains the post url.

wp pmc-post-fields fix-slugs --csv-file=file.csv --dry-run=false

Remove old slug

The CLI command removes _wp_old_slug postmeta for given 'Slug' OR 'CSV containing Post IDs' (each per line).

For some brands, multiple posts were saved with the same slug and _wp_old_slug postmeta while migrating from old website which confuses the default WordPress' redirect engine and redirects URL incorrectly due to multiple posts having the same 'slug'. Ex: More than 150 Ask Billboard posts on BillBoard saved with ask-billboard in _wp_old_slug postmeta.

// Removes `_wp_old_slug` postmeta for the given Post IDs, no matter what value it holds.
wp pmc-post-fields remove-old-slug --csv-file=file.csv --dry-run=false
 
// Removes `_wp_old_slug` postmeta if it holds `ask-billboard` value in it from all the posts of any post type.
wp pmc-post-fields remove-old-slug --slug='ask-billboard' --log-file=script.log wp pmc-post-fields remove-old-slug --dry-run=false

Remove broken links

The CLI command removes broken links from the post_content for given list of URLs (in CSV).

Required parameters: --csv-file accepts full path to the CSV file.

The CSV must contain two columns: Post URL and Broken Link

wp pmc-http-cleanup remove-broken-links --csv-file=file.csv --dry-run=false

Remove broken links - Globally

The CLI command removes broken links from the post_content from the given post type posts.

Required parameters:

  1. --post-type accepts post type. Default: any.
  2. --log-not-found-urls whether to log not found URLs in log file. Default: true.
  3. --csv-file accepts full path to the CSV file.

Useful parameters:

  1. --batch-size to perform script in chunk-wise. Default: 100.
  2. --offset to skip number of posts before processing. Default: 0.

The CSV must contain a column: Broken Link

wp pmc-http-cleanup remove-broken-links-globally --csv-file=file.csv --dry-run=false

Note: This could be resource intensive script, so it is recommended to run script batch-wise, for a single post-type at a time.


Replace defunct links

The CLI command replaces defunct URLs with actual URLs for given list of URLs (in CSV).

SEO reported many URLs were containing defunct subdomain (domain is not in use). However, they found many of them could legitimately be matched to existing pages based on the slug. For ex: http://api.hollywoodreporter.com/live-feed/nbcs-bob-greenblatt-still-room-594409 (opens in a new tab) matches with https://www.hollywoodreporter.com/tv/tv-news/nbcs-bob-greenblatt-still-room-594409/ (opens in a new tab).

This CLI script will grab the slug of the given defunct link, check whether any post available matching the slug and replace the whole URL with matching post URL if any.

Required parameters: --csv-file accepts full path to the CSV file.

The CSV must contain two columns: Post URL and Defunct Link.

wp pmc-http-cleanup replace-defunct-links --csv-file=file.csv --dry-run=false