1

I've added a myvar/myvalue rewrite endpoint to EP_ALL which can be added to any URL of a WP installation and a WP plugin will act upon it. That part is cool but it doesn't work when the permalink structure is /%category%/%postname%/. It works well with all the built in, selectable structures. There could be other structures it doesn't work with.

Doesn't work = 404 error.

The path looks something like this: /mycategory/mypost/myvar/myvalue

I got the Rewrite analyzer plugin which tells me that it's interpreted as (top 4, in order):


This is not it... (highlighted with yellow)

(.?.+?)/myvar(/(.*))?/?$
pagename: mycategory/mypost
myvar: myvalue


Apparently this gets used but it's still cold...

.?.+?/([^/]+)/myvar(/(.*))?/?$
attachment: mypost
myvar: /myvalue


Plain wrong...

(.?.+?)(/[0-9]+)?/?$
pagename: mycategory/mypost/myvar
page: /myvalue


This is it, but it fails to realize it!

(.+?)/([^/]+)/myvar(/(.*))?/?$
category_name: mycategory
name: mypost
myvar: myvalue


And I'm outputting global $query_string; which tells me it's
attachment=mypost&myvar=%2Fmyvalue (by the way it shouldn't include the %2f - slash).

So can someone enlighten me if this is a bug in WP, or is there something I can do about it?

My idea is roughly this
if ( '/%category%/%postname%/' == $wp_rewrite->permalink_structure ){ ... }
and manually telling WP the category and the name and displaying that content. But I don't know what goes as ... and what should I hook this into.

2

Why doesn't it work? I'm not sure. That particular pattern is the same as a parent/child page request, WordPress has to do some extra queries to determine if a post exists by that name, or if it's a page. Why this breaks when you add an endpoint, I haven't delved into the code to determine.

How can you make it work? It appears that if you don't use the EP_ALL mask and instead use the OR operator with all the individual masks, it will build the rules in such a way where those endpoints will correctly resolve.

For example:

function wpa_myvar_endpoint(){
    add_rewrite_endpoint( 'myvar', EP_PERMALINK | EP_PAGES );
}
add_action( 'init', 'wpa_myvar_endpoint' );
2
  • HA! It works, thank you. The rewrite analyzer puts the previously 3rd and 4th row into the 2nd and 3rd position by having that 2nd row with the attachment + myvar interpretation completely gone! Is your EP_PERMALINK | EP_PAGES equivalent to EP_ALL in practice? I really need the myvar/mayvalue combination to be able to be added to any URL. Sep 21 '13 at 10:30
  • add_rewrite_endpoint($this->settings['myvar'], EP_PERMALINK | EP_DATE | EP_YEAR | EP_MONTH | EP_DAY | EP_ROOT | EP_COMMENTS | EP_SEARCH | EP_CATEGORIES | EP_TAGS | EP_AUTHORS | EP_PAGES); looks quite interesting, I'm omitting just the EP_ATTACHMENT. Sep 21 '13 at 11:37

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.