3

After permanent trashing/deleting a previous page with the same permalink, I still can't make a page save its permalink without the "-2" added to the end. How should I solve this problem?

Choosing "Quick edit" and change the slug and save will not change the permanent link too. I'm not familiar with Wordpress coding or working with database inside phpmyAdmin. If I have to deal with changing SQL, please advice me in steps and easy way. Thank you in advance.

  • Is there a post or image that could have that permalink? – ngearing Jul 27 '16 at 5:48
  • No, there is not a post or a image that have that permalink. – Kami Jul 27 '16 at 6:00
  • did you delete it from trash too ? deleted post goes to Trash – abhirathore2006 Jul 27 '16 at 7:34
  • Yes, as I mentioned above. I have permanent deleting them all. – Kami Jul 27 '16 at 8:53
2

There is a function that is looking for duplicated post names: wp_unique_post_slug.

In this function are few queries, and one of them is looking for duplicated post names: SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1. If this query will return some rows then function will add suffix to post name. So you have to have some post with identical post name and post type, but with different post id than this one, which you are editing.

You can check this by editing this query and executing it in phpMyAdmin for example. This should looks like this: SELECT post_name FROM wp_posts WHERE post_name LIKE "your_post_name%" You need to change wp_ to your tables prefix and your_post_name to your post name (percent sign is important)

wp_unique_post_slug on trac

  • Thank you for the guide. I'm a little lost here. I dont understand, where I should check this up? Inside phpmyadmin or? I'm sorry, if you could lead be step by step I will appreciate it. – Kami Jul 27 '16 at 9:53
  • Inside phpMyAdmin you have to select database from left sidebar, go to your wp_posts table and then click on top menu "SQL". You can insert there SQL query and execute it. – Krzysztof Grabania Jul 27 '16 at 10:10
  • I'm sorry for stupid question. how can I find my tables prefix? – Kami Jul 27 '16 at 10:16
  • Into your wp-config.php file: $table_prefix = 'wp_'; – Krzysztof Grabania Jul 27 '16 at 10:18
  • sorry, I got it. MY tables prefix is wp_ytza_. I found this by clicking on wp_ytza_posts. – Kami Jul 27 '16 at 10:18
0

You can try a plugin like wp-optimize, but if the page is still stuck, it sounds like your database is in a strange state for that page.

You'll need to find out the name of your WordPress database by logging in to your site host and then opening up phpmyAdmin.

Click on the '+' next to the database name to expand the tables. If you only have one instance of WordPress installed, when you find the right database, you'll see a table named 'posts'. For security, sometimes some random characters are added to it, so it will look like 'sdfJEdssposts' instead of just 'posts'.

Now click on the 'SQL' tab on the top of the right hand pane in phpmyAdmin. Inside the box, paste in the following SQL query:

select * from <posts_table_name> where post_title='<permalink>' and post_type='page'
  • For <posts_table_name> type in whatever the table with the 'posts' suffix is named.
  • For <permalink>, use the name of the page whose permalink keeps getting the -2 added to it. Don't use the entire url, just the page name. For example, for http://www.example.com/pagename, you would only use pagename.

For SQL, keep the single quotes but don't use the angle brackets.

It should bring back a single row that has the page information with an option to delete that row. Click on 'Delete' and that page should be cleaned out of your database for good.

  • Thanks for the guide. I have these two lines now in my SQL. SELECT * FROM wp_ytza_posts WHERE 1'` and select * from <wp_ytza_posts> where post_title='<catering-3>' and post_type='page'... I am not sure if I entered <posts_table_name> correctly? .... Once I delete it, will my catering-3 page be deleted? Because I don't want that page to be deleted, but just be able to name that page to "catering" without "3". – Kami Jul 27 '16 at 9:45
  • Also one question please. After writing in the code. Which bottom should I select. There are 8 buttons. SELECT*, SELECT, INSERT, UPDATE, DELETE, clear, Format and Get auto-saved query. – Kami Jul 27 '16 at 10:12
-1

Get into the database and delete the posts, which may still be there even though trashed and "removed".

Might want to start with:

select * from wp_posts where post_name like '%the-slug%';

Then

delete from wp_posts where post_name like '%the-slug%';

or

delete from wp_posts where post_name = 'the-slug';
  • 1
    deleting directly from the DB is always a bad idea as you can never know what kind of garbage will be left behind (most likely at least meta) – Mark Kaplun Sep 18 '18 at 18:03

Your Answer

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

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