2

The title may be a little confusing, I don't know how to word it to be short.

Right now my permalink structure is /%post_id%/%postname% so the final URL is /post_type/%post_id%/%postname%.

When I go to domain.com/post_id then it redirects to domain.com/post_type/%post_id%/%postname% but when I got to domain.com/post_type/post_id it doesn't redirect but shows the correct post.

I'm not sure how to make it work the way the default redirect works.

1
  • 1
    By default, a custom post type wouldn't adhere to the permalink structure. Are you overriding the rewrite base in your register_post_type() call? If so, what are you setting it to? May 29, 2013 at 1:24

1 Answer 1

4

I used the following plugin lately:
https://github.com/kasparsd/numeric-shortlinks
to get post ID based shortlinks, like http://domain.com/123. That worked very well for me, with a couple of custom post types too.

On a sidenote, I'm not sure about your permalink structure, especially because %post_id% and %postname% are both uniquely referring to the same post, but on the other hand you might have a good reason for choosing the structure exactly like that.

In reference to Matthew's comment i used the following in my register_post_type() call in above mentioned project:

        'rewrite'   => array(   'slug' => '/%post_type%',
                                'with_front' => false,
                                'pages' => true,
                                'feeds' => '',
                                'ep_mask' => 1 )

It's just the rewrite part and of course you have to replace %post_type% accordingly - I also should mention that the settings for the permalinks would be set to just %postname%.

3
  • You've got me pretty freaking close. I've added the plugin and set up my rewrites like you have but the post ID isn't staying in the URL it's being removed on the redirect. I tried adding this pastebin.com/tJX5Gh9T -- the post ID stays in the URL but it gets a 404 page.
    – kel
    Jun 25, 2013 at 23:33
  • @kel: I'm not sure if I understand the remaining problem correctly, totally. It might be a good case for a new question. Jun 26, 2013 at 20:16
  • I actually had to remove the numeric shortlinks plugin because when I would got to page 2 of a post it would redirect to the post/page that had the ID of 2. I created a new post that explains better what I'm looking for and what I've tried. wordpress.stackexchange.com/questions/104394/…
    – kel
    Jun 26, 2013 at 20:52

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.