It is possible to use this as a permalink for a post:
/%category%/%postname%/
But lets say I’ve created a taxonomy called “artist”. I’d like to use this for my posts:
/%artist%/%postname%/
I know that taxonomies allow you to list their terms with this:
/%artist%/%someartist%/
but that is not what I’m looking for. I want to modify POST urls, not taxonomy ones.
I’m trying this on my blog and it is not working. Is this something that can be done in WordPress?
Assuming your custom taxonomy is called
artist
(and you don’t override the slug in therewrite
parameter) you can use the rewrite tag%artist%
. WordPress implements almost every functionality to use those rewrite tags in post permalinks. There are only a few small adaptations necessary.Building the Permalink
First, you’ll need to use the
post_link
filter to replace a custom »tag« in your request structure:This function (
wpse_56769_post_link
):no_artist
) which is used as fallback if the post as no assigned terms in the artist taxonomy,%artist%
with the slug of this term.Now, go to the menu Settings â Permalinks, choose the option »Custom Structure« and write in:
/%artist%/%postname%/
.In the result, a post permalink should look like this:
Now that the post permalinks inkludes the first artist term slug, let’s have a look to the routing.
Update the permalinks (Routing)
You will notice, that the permalink is resolved correctly to the single post. Unfortunately, page permalinks are broken.
To solve this problem, you don’t necessarily need to alter the rewrite rules. The only thing we need to do is to change the internal state of
WP_Rewrite
. The propertyWP_Rewrite::use_verbose_page_link
needs to be set toTRUE
. (This is the internal behaviour ofWP_Rewrite
when using%category%
or%author%
tags as base for post permalinks.)The state has to be changed at two points:
do_parse_request
becauseWP::parse_request()
asks for this state andpage_rewrite_rules
for when the rewrite rules gets build.Now, the routing is fixed and page permalinks works well. (After flushing the permalinks once again.)
Handle the
no_artist
pseudo termOne last thing on the
no_artist
thing: If the post really is not assigned to any term of theartist
taxonomy, the permalink is parsed to the following query variables:This should lead to a 404 because the term doesn’t exists. As the post’s
name
should be unique we can remove theartist
query variable on therequest
filter:With that filter, a post like
http://wordpress.dev/no_artist/sample-post/
will be found properly.I think this is what your looking for:
Custom Post Type Permalinks
This plugin lets you edit the permalink structure of custom post type.
To install this plugin:
your /wp-content/plugins/ directory.
You can also go to the ‘Plugins’ menu in your wordpress and click “add new”. Then find this plugin by searching for “Custom Post Type Permalinks” and install it by clicking the install button.
A new item will appear in the menu on the left of your wordpress admin. Here you can change the settings depending on your needs (names of the taxonomies etc).
Futhermore my site currently has the following permalink structure “site.com/star/aristname/” which then list all posts for this artist or a page/post about this artist.
If your looking for this you can create an archive page for your custom post type. WordPress will automaticly assume this structure. For more information on how to create your own archive page please go here. (If your indeed looking for this, I can explain it more thoroughly if you want)
Whan i wanted to hook url to category (in any url structure) i set a list of terms into url rewrite structure , but in my case there was not much terms…
the results was something like
rewrite rule key
and rule value
everything was hooked using rewrite_rules_array filter.
result you can see at http://unu.edu/publications