Deleted Page Still In WordPress Database

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.

Topic permalinks Wordpress

Category Web


UPDATE: Actually this is not a good idea, as noted in comment below.

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';

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.


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

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.