Support » Plugin: Permalink Manager Lite » Auto permalink guess issue with “Duplicate this” plugin

  • Resolved morespinach

    (@morespinach)


    Hello. We use Permalink Manager Lite along with a helpful Duplicate This plugin that allows us to create complex records more quickly (many custom fields, which come pre-populated so with some quick edits the whole post is quickly ready).

    The challenge is that the way Permalink Manager Lite is guessing the unique URL for the just-created duplicate post (not yet saved, just created) is weird. It’s adding random digits to the URL.

    For example if this is the permalink of the original custom post:

    category/automotive/cars/ford-catches-fire-due-to-road-debris

    After duplicating, it’s guessing it to:

    category/automotive/cars/ford-catches-fire-due-to-road-debris-2-3-2-2-2-2-2-3-2-3

    Where are all those 2s and 3s coming from? How can we fix it to be just a -2 or something simple?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi again @morespinach,

    when you duplicate the post, WordPress adds the numeric index to the end of native slug to make the post slug unique.
    https://permalinkmanager.pro/docs/faq/native-slug-in-wordpress-permalinks/

    If you duplicate, the post that were duplicated before, the numeric index will be preserved.

    Orignal post:
    category/automotive/cars/ford-catches-fire-due-to-road-debris

    First duplicate:
    category/automotive/cars/ford-catches-fire-due-to-road-debris-2

    Second duplicate (duplicate of first duplicate):
    category/automotive/cars/ford-catches-fire-due-to-road-debris-2-3

    and so on.

    I would recommend to manually adjust the custom permalink to make it unique. If you would like to strip the duplicated indexes, you can use this code snippet:

    function pm_filter_default_post_uris($default_uri, $native_slug, $post, $slug, $native_uri) {
    	return preg_replace('/([\d-]+)$/', '-2', $default_uri);
    }
    add_filter('permalink_manager_filter_default_post_uri', 'pm_filter_default_post_uris', 999, 5);

    Best regards,
    Maciej

    • This reply was modified 2 months ago by Maciej Bis.
    morespinach

    (@morespinach)

    Thank you. Let me try this. The issue is that the third time the second duplicate is saved, the URL is not

    category/automotive/cars/ford-catches-fire-due-to-road-debris-2-3

    Instead, it is something much longer:

    category/automotive/cars/ford-catches-fire-due-to-road-debris-2-2-2-2-2-3-3-3-3-3

    Something like that. Anyway, let me try your code. Thanks!

    morespinach

    (@morespinach)

    This “works” I think, but now the ‘native slug’ is coming up empty.

    The default permalink is the same as the original. So I change it manually to add a “2” or something. But the native slug is totally empty even when I save this new permalink.

    Is this an issue? What should I do to fix that

    Plugin Author Maciej Bis

    (@mbis)

    The native slug is empty, if the duplicated post status is set to “draft”. The slug is generated only after the post is published unless you change/adjust it manually. It should work exactly the same way even if my plugin is not active.

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.