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.

I have, with help from Milo managed to tweak the permalinks for my custom post type so that they include the year and month of the event. e.g.

  • mysite.com/events/2013/january/fishing-trip
  • mysite.com/events/2013/may/picnic
  • mysite.com/events/2013/may/visit-grandma

One small issue still evades me. If there is more than one event with the same name, WordPress appends a number to the end of the name even when the month is different and so there is no need for the name to be unique.

In other words I get

  • mysite.com/events/2013/january/fishing-trip
  • mysite.com/events/2013/may/picnic
  • mysite.com/events/2013/june/fishing-trip-2

when I want

  • mysite.com/events/2013/january/fishing-trip
  • mysite.com/events/2013/may/picnic
  • mysite.com/events/2013/june/fishing-trip

Is there a solution for this? I've got permalinks set to "postname" in permalink settings if this matters.

share|improve this question
    
may want to include the code that Milo gave you? –  WP Themes Jan 31 '13 at 21:53
    
    
Did you ever find a fix for this? I'm interested as well. TIA –  NW Tech Mar 7 '13 at 7:49
4  
This is normal WP behaviour - there's not really a bug to fix. WP will append a number to any post with a duplicated name - regardless of the rest of the address. –  vancoder Mar 14 '13 at 23:31
    
A potential solution would be to use the month and year as part of the slug and drop it from the rewrites. It would ensure unique slugs and work around the issue you're describing. –  t31os Apr 13 '13 at 12:50
add comment

1 Answer

There is a plugin for wordpress which allows you to handle 404 errors and redirect to specific pages. So if wordpress calls your post /events/2013/june/fishing-trip-2, you could go into the plugin and add a rule so that /events/2013/june/fishing-trip points to /events/2013/june/fishing-trip-2.

It's not a perfect solution, as you'd have to manually enter each duplicate post name to the rewrite rules, and even then the links wordpress generates for that post would still have the -2. You could write a function using preg_replace to then remove any -2 or -3 or whatever from the end of a link, but it's a little messy

share|improve this answer
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.