This is similar to this, but I am not using the Perl module.
Problem
I am using WordPress 4.3 and I need to add a number like 1122000
to post_id
for permalinks structure.
This is what I have as default URL structure:
mysite.com/?post_type=orders&p=139
and this is desired permalink structure:
mysite.com/orders/1122139
Please note that we can't just concatenate 1122
into the post_id
as post_id
may exceed 999
at future.
My efforts
In my first try I used add_rewrite_rule
function:
function my_rewrite_basic() {
add_rewrite_rule( '^orders/1122([0-9]+)/?', 'index.php?post_type=orders&p=$matches[1]', 'top');
}
add_action('init', 'my_rewrite_basic');
Which works only if id is lower than 1000
.
In my second try I directly used Apache RedirectMatch like this:
RedirectMatch 301 ^/orders/(\d+) /?post_type=orders&p=($1-1122000)
in .htaccess
file with no success.
Is there another way to implement a 7 digit serial number based on post_id?