Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
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? –  Matthew Boynes May 29 '13 at 1:24
add comment

1 Answer

up vote 3 down vote accepted

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%.

share|improve this answer
    
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 '13 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. –  ialocin Jun 26 '13 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 '13 at 20:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.