I need to remove/delete slug of posts on pending via phpMyAdmin. Most of posts on pending have slug/URL which is different from their post title, deleting post slug/URL will force WP to generate new slug when post is published (which will be then as post title).

Just for test, I tried manually to delete slug from some posts on pending via phpMyAdmin, and than to publish it via WP, and new slug is generated from post title. Now, I just need SQL function/query for that.

So, I need to delete slug only from posts and only from posts on pending.

I think it should be something like this:

UPDATE wp_posts SET post_name = '' WHERE post_status = 'pending' AND post_type = 'post';

Could someone verify that please (or fix it if needed)?

1 Answer 1


One disadvantage of using that SQL query is that the slug will only be updated when you really go edit the post. Plus, it might cause odd behavior when any plugin tries to do something with an empty slug.

A good alternative would be to use WP-CLI instead.

First, you'll need a list of all pending posts:

wp post list --post_type=post --post_status=pending --format=ids

Next, you need a way to remove the slug of a post:

wp post update <id> --post_name=""

Now you can combine these commands like this:

wp post update $(wp post list --post_type=post --post_status=pending --format=ids) --post_name=""

This way, the post update will happen through WordPress' internal API instead of just SQL.

  • My plan was to update it via phpMyAdmin, than to go to WordPress admin and bulk select pending posts and edit--> publish them. Commented Jan 22, 2018 at 14:39
  • I am not familiar with WP CLI, how fast will be that operation comparing to pHpMyAdmin? And most of all, do you think that my SQL code is correct or not? Commented Jan 22, 2018 at 14:41
  • 1
    Maybe I will spend some time learning WP CLI, thank you suggestions. Commented Jan 22, 2018 at 14:42
  • Have you tried the SQL code on a test installation? It looks correct at first glance, but you have to try it in order to find out. Running WP-CLI involves PHP, which will always be slower than just a plain SQL query. However, it's definitely way faster than running the SQL query and bulk editing all your posts.
    – swissspidy
    Commented Jan 22, 2018 at 14:42
  • 1
    Thank you, I already marked your answer as useful, now I accepted it ;-). If I need more help about WP-CLI I hope you will be able to help me more. Commented Jan 23, 2018 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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