WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to customize single post permalink (the structure of the permalink) if posts have a certain value in a certain custom fields.

I use the filter post_link to change permalink when needed, and this works greatly (I mean, in front-end permalink are different when they should).

First question: in your opinion I have to use other filters to cover all cases of single post permalink customization?

Then I have added specific rule using add_rewrite_rule to interpret this new kind of structure, and here I face the problem.

As this permalink structure has the ID (with 0 at the beginning in order to reach 6 digit, ex. 008467) at the end, I notice that Wordpress redirects to a new url with this number - cast to an integer - repeated, for example:





Do not worry about the structure before POSTSLUG, in fact the important thing is that if I remove the POSTID from the structure (008647) all works fine! For example, the following works:


How is it possible?! It seems that Wordpress thinks that number is something different, like pagination or something similar.

This is the rule I have added (the regexp is correct, I have tried it with an online tester):

share|improve this question
It's hard to diagnose this without seeing all of your code, but I'm guessing the issue is the fact that you're forcing the post id to be 6 digits. Is there any reason why you can't change that to ditch the leading zeros? – Matthew Boynes May 23 '13 at 20:02

Your Answer


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

Browse other questions tagged or ask your own question.