Support » Fixing WordPress » Mass Rename Permalinks

  • mastastealth


    I’ve been trying to fix up a comic blog that had imported all the archives from a blogger page. Unfortunately I didn’t realize the first time that not all the comments had imported, so after reimporting, I ended up with a bunch of duplicates. I managed to delete all the posts without comments, leaving the 2nd reimported ones there (all manually unfortunately) which leaves me to my last task:

    All the reimported posts have a “-2” at the end of the permalink. I’ve changed a few manually but I can’t go erasing that last bit on 900+ posts! I already emptied the trash of the last posts, deleted .htaccess and tried regenerating permalinks but nothing! I checked on SQL but it doesn’t seem that when I change something in the post_name entry it affects WordPress, or vice-versa.

    I think what I need is a simple plugin that can search all the permalinks for an ending “-2” and just chop that bit off. Does anyone know if there is a command in SQL, PHP script, or plugin I can use to do this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Darrell Schauss


    For SQL:

    UPDATE [table_name] SET [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');

    Something like.. example (not tested!). Don’t forget wp_prefix_ if have one.
    UPDATE wp_posts SET post_name = replace(post_name,'-2','');

    This might be better so you only get the -2 on the ends and not ones that have it in between.

    UPDATE wp_posts SET post_name = replace(post_name,'-2','') WHERE post_name LIKE '%-2';



    Ok, that definitely cleared the SQL stuff, but how do I have WordPress update or refresh itself with the changes?

    The odd thing is, I can take off the “-2” on the link, and it works, although it just gets redirected to the “-2” again. (Except the few that I quick-edit, those work only with the original name, and not the “-2” ending version, which is what I want it to do)

    Darrell Schauss


    I have made permalink changes in the database on very small amount of pages and changes were instant. Maybe cleaning up all the revisions can help. Not sure.

    DELETE FROM wp_posts WHERE post_type ='revision'

    I know manually changing a permalink to one that already exists elsewhere; it wont change. Do some post URLs end up matching when they have all their -2 removed? With 900+ a wild guess you might so happen to have two posts same name?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Mass Rename Permalinks’ is closed to new replies.