1

Weekly archives are nearly undocumented, but WordPress can produce them, which I want. Good. But the URLs are ugly, eg. http://example.com/?m=2020&w=18

This gets partially rewritten to /2020/?w=18 from somewhere but I'd like it if I could get the whole thing cleaned up, say as /2020/week-18.

I can get to /week/2020/18 via:

function custom_rewrite_rule() {
    add_rewrite_rule('^week/([0-9]+)/([0-9]+)/?','index.php?m=$matches[1]&w=$matches[2]','top');
}
add_action('init', 'custom_rewrite_rule', 10, 0);

…but moving the text in, ie. ^/([0-9]+)/week-([0-9]+)/? fails and I just get 404s.

What am I doing wrong? Or is it just conflicting in some way with whatever rule is doing that partial cleanup? And if so is that addressable?

(Yes, I'm flushing the rules via admin between attempts.)

1
  • While I am not recommending you to change core, as an analytical method, you may go to class-wp.php line around 207 -260, you could var_dump the result and exit() after the loop and see what WP found. Your regex seems ok. There's maybe some other factors. May 6, 2020 at 5:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.