Support » Plugin: Permalink Manager Lite » Both change permalink and redirect to new url?

  • Resolved ctrlaltdelete

    (@ctrlaltdelete)


    Hi, i want to make sure before installing if this is the right plugin for the task.
    I have several Custom post types.
    I want to change the current permalink:
    domain.com/cpt1/%postname%/
    to
    domain.com/cpt1/%post_id%/

    And i also need it to redirect the old urls to the new ones. Preferably a 301 redirect.

    And i want to know if there would be a performance hit for doing this with say 6000 posts.

    Thanks.

Viewing 15 replies - 16 through 30 (of 36 total)
  • Wow so fast! So this is pretty much finished for production, i just install the latest version and add the function to the theme and done.
    Thanks so much!

    Plugin Author Maciej Bis

    (@mbis)

    @ctraltdelete

    If you encountered any problems related with 404 error on pages where you use pages’ IDs instead of slugs after you updated Permalink Manager to 1.0.2 version – please disable & remove the plugin and reinstall it again (the freshest revision contains correct REGEX rule, which is used to detect the custom URIs).

    Sorry for trouble,
    Maciej

    ctrlaltdelete

    (@ctrlaltdelete)

    Thanks for the update!

    ctrlaltdelete

    (@ctrlaltdelete)

    Hello, it’s working as expected for existing posts but when creating a new post, it ends up with this url:

    http://domain.com/custom-post-type/67986/the-post-title/
    instead of:
    http://domain.com/custom-post-type/67986/

    Plugin Author Maciej Bis

    (@mbis)

    Hi @ctrlaltdelete,

    please confirm, the incorrect URI is displayed in “Edit URI” box (below post title) after the post is saved?

    Best Regards,
    Maciej

    ctrlaltdelete

    (@ctrlaltdelete)

    Yes exactly! After saving you can already see it there, and after clicking publish it’s still there (unless you manually remove it i guess).

    Plugin Author Maciej Bis

    (@mbis)

    Hi @ctrlaltdelete

    please disable and remove the plugin & install a fresh copy.

    After that please add this hook:

    function permalink_manager_filter_draft_slug($slug, $post) {
    	if(in_array($post->post_type, array('YOUR_CUSTOM_POST_TYPE_1', 'YOUR_CUSTOM_POST_TYPE_2'))) {
    		return '';
    	}
    }
    add_filter('permalink_manager_filter_default_post_draft_slug', 'permalink_manager_filter_draft_slug', 99, 2);

    Let me know if it helps.

    Best Regards,
    Maciej

    ctrlaltdelete

    (@ctrlaltdelete)

    Now new posts have nothing as slug. A new single post under CPT1 will have this url:

    http://domain.com/CPT1/

    Exact same as the archives of that CPT.

    Plugin Author Maciej Bis

    (@mbis)

    Could you try this instead of the previous snippet?

    function permalink_manager_filter_draft_slug($slug, $post) {
    	if(in_array($post->post_type, array('YOUR_CUSTOM_POST_TYPE_1', 'YOUR_CUSTOM_POST_TYPE_2'))) {
    		return "/{$post->ID}";
    	}
    }
    add_filter('permalink_manager_filter_default_post_draft_slug', 'permalink_manager_filter_draft_slug', 99, 2);
    ctrlaltdelete

    (@ctrlaltdelete)

    Now it works well for new posts! but doing “Regenerate/Reset” -> “FULL URIs” reverts it back to the “pretty permalink”

    Plugin Author Maciej Bis

    (@mbis)

    @ctraltdelete

    It looks like the previous hook is lost in your functions.php, please try this code:

    function permalink_manager_filter_slug($slug, $post, $post_name = '') {
    	if(in_array($post->post_type, array('page'))) {
    		$slug = "/{$post->ID}";
    	}
    	return $slug;
    }
    add_filter('permalink_manager_filter_default_post_slug', 'permalink_manager_filter_slug', 99, 3);
    add_filter('permalink_manager_filter_default_post_draft_slug', '__return_null', 99);
    add_filter('permalink_manager_deep_uri_detect', '__return_true');

    In case you encounter 404 errors, please again reinstall the plugin. I added another filter that widens the REGEX function used to detect the posts.

    ctrlaltdelete

    (@ctrlaltdelete)

    Oh i didn’t think i needed both, sorry.

    With the new one when creating a new post the “Edit URI” box (below post title) puts 2 slashes instead of one, example:
    http://domain.com/CPT1//4864

    So when you view the post it’s 404.
    BTW i tested after redownloading the plugin.

    Plugin Author Maciej Bis

    (@mbis)

    @ctraltdelete

    did you reinstall the plugin again?

    A while ago, I added another filter that allows to bypass 404 error when post IDs are used instead of slugs – by default the post IDs are treated as page numbers of pagination.

    ctrlaltdelete

    (@ctrlaltdelete)

    Yes i did reinstall it.
    I created a post after saving draft i noticed there was an extra “/” before the ID as shown on the post above. I published the post. And when i try to view it it 404.

    So i edited the post and manually removed the extra “/”, now the post works fine.

    I think my setup is fine it’s just that the extra “/” shouldn’t be there. I don’t know what changed that it appears there.

    Maybe i should use 2 different snippets 1 from page 1 for mass convert and 1 from this page for new posts instead of combining both into 1 snippet that causes the double slash. Should i do that?

    Plugin Author Maciej Bis

    (@mbis)

    Hi @ctrlaltdelete,

    please remove the slash from the snippet above, this should help

    $slug = "/{$post->ID}";

    should be replaced with:

    $slug = "{$post->ID}";

Viewing 15 replies - 16 through 30 (of 36 total)
  • The topic ‘Both change permalink and redirect to new url?’ is closed to new replies.