How can I add extra parameters after a permalink, specifically if I’m using a custom post type?
For example, let’s say http://mysite/album/record-name
was the permalink. How can I make http://mysite/album/record-name/related
not turn up a 404 or redirect?
WordPress doesn’t seem to call up the post template if the post doesn’t exist… so I’m at a bit of a loss how to do this.
You can add an endpoint to your URIs to handle special requests.
Here is a basic example as plugin. To understand what’s going on read Christopher Davis‘s fantastic tutorial A (Mostly) Complete Guide to the WordPress Rewrite API.
You can do this with the Rewrite API‘s add_rewrite_endpoint:
In the template you can detect when your related query var is present:
to add parameter to post url (permalink), i use like this:
output:
http://yoursite.com/pagename?my_pid=12345678