I'm using WP-CLI to import articles from a non-WordPress system. The legacy system has a custom URL defined for every post. I'd like to be able to set the permalink on the posts I'm importing base on the custom URL defined in the legacy system. I don't need to set the entire permalink, just being able to set the suffix, as is supported in the WP admin UI, would be sufficient. But there doesn't seem to be a way to change the permalink for a specific post using WP-CLI. Am I missing something?

up vote 2 down vote accepted

If you mean the post name field, then we can update it for a post with:

wp post update 123 --post_name="new-slug"

where 123 is the post ID.

If we then try to update another post with the same post name:

wp post update 321 --post_name="new-slug"

then it will be set to new-slug-2 in that case, as it needs to be unique. If we continue this with other posts, then we will get new-slug-n where n is a positive integer.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.