0

I've setup a static posts page named "Journal", mydomain.com/journal.
This page now lists my 15 latest posts. All fine this long.

I'm able to access each post individually by going to mydomain.com/postname. I want to change this so I'm able to access each post individually by going to mydomain.com/journal/postname.

If I change the permalink structure to mydomain.com/journal/%postname%/ I can access posts with a permalink like mydomain.com/journal/im-just-a-regular-post/ just fine.

But if I go with a numeric permalink so I end up with an url such as mydomain.com/journal/12345 or a more complex (the endgame here) such as mydomain.com/journal/99058672222 it'll just serve me up the content of the posts page without even redirecting me.

If I revert the permalink settings to mydomain.com/%postname%/I can access my post at mydomain.com/99058672222 just fine. Why's that? Can I get around this somehow?

UPDATE I installed Debug Bar

This is what I get with mydomain.com/journal/regular-old-post

Request:

journal/regular-old-post

Query String:

name=regular-old-post

Matched Rewrite Rule:

journal/([^/]+)(/[0-9]+)?/?$

Matched Rewrite Query:

name=regular-old-post&page=


And with mydomain.com/journal/99058672222 I get:

Request:

journal/99058672222

Query String:

page=%2F99058672222&pagename=journal

Matched Rewrite Rule:

(.?.+?)(/[0-9]+)?/?$

Matched Rewrite Query:

pagename=journal&page=%2F99058672222


I can clearly see that they're different but I know too little about the mechanics of how the rewriting stuff works in WP. Any pointers?

  • maybe this is your issue? – Milo Oct 6 '14 at 0:43
  • Is the name of the post 99058672222 or is that the post ID ? – nothingtosee Oct 6 '14 at 2:41
  • @nothingtosee I've set the permalink to 99058672222 manually, the name is actually something else. – INT Oct 6 '14 at 9:21
  • @Milo I applied that piece of code, but no luck.. – INT Oct 6 '14 at 9:27
0

With some help I was able to get it working with this:

add_action('init', 'journal_urls');
  function journal_urls() {
      add_rewrite_rule(
          '^journal/([^/]*)$',
          'index.php?name=$matches[1]',
          'top'
      );
  }

Maybe someone can benefit from this in the future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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