pgt
Veteran
Just Getting Started
Member Likes (0)
I'm looking for the best way to add a taxonomy slug into the permalink structure.
For example, for example, for a "Format" taxonomy with choices Bio, Photos, Videos:
Permalink Structure: /%category%/%format%/%postname%/
Category: John Travolota
Format: Bio
Result: http://example.com/john-travolta/bio/this-is-a-bio-post
Post without a "Format" taxonomy chosen: http://example.com/john-travolta/this-is-a-regular-post
This plugin http://wordpress.org/extend/plugins/post-format-permalink/ seems to target this issue, however any post without a "Format" chosen results in a 404 error.
Thanks in advanced!

Responses (7)
People Person (joined February 2012) Likes (0)
pgt,
Hi and Thanks for using WPMUdev forums!
It seems that error is the one that makes the plugin you reference hard to use. Seems no-one can get it to work since the latest WP updates.
http://wordpress.org/support/topic/plugin-post-format-permalink-404-error?replies=4
That's a link to the last supported thread for that plugin.
Here is some great info about adding custom taxonomies to your permalink structure as well as translating them properly (this is what commonly causes the 404 error)
Let me know if this helps :)
Kimberly
Member (joined March 2012) Likes (0)
Thank you Kimberly, did you forget to post the second link about adding taxonomies to permalinks?
People Person (joined February 2012) Likes (0)
You caught me! :)
Friday was a CRAZY day and I guess my copy/paste got lost in space!
Let's try it again:
http://shibashake.com/wordpress-theme/add-custom-taxonomy-tags-to-your-wordpress-permalinks
and a langinappe:
http://www.viper007bond.com/2011/10/07/code-snippet-helper-class-to-add-custom-taxonomy-to-post-permalinks/
Any progress over the weekend? :)
Member (joined March 2012) Likes (0)
Hi Kimberly,
Thanks for the help. I've been able to achieve the permalink structure I am looking for using the following code:
add_filter('post_link', 'brand_permalink', 10, 3);
add_filter('post_type_link', 'brand_permalink', 10, 3);
function brand_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%brand%') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'brand');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {
$taxonomy_slug = $terms[0]->slug;
return str_replace('%brand%', $taxonomy_slug, $permalink);
}
else {
$taxonomy_slug = '';
$new_permalink = str_replace('/%brand%', $taxonomy_slug, $permalink);
return $new_permalink;
}
}
If I go to a post with the taxonomy "Label" set, it works fine. However, whenever I click on a post that doesn't have a "Label" taxonomy set, the permalink structure is okay, but it directs to a Category page for the post rather than the actual Post.
My current permalink structure: %category%/%brand%/%postname%/
Looking to achieve: http://mysite.com/shoes/nike/this-is-a-post-title , where Shoes is the Category, and Nike is the Brand.
If there is no "Brand" selected: http://mysite.com/shoes/this-is-a-post-title
Again, the code above gives the posts the right structure, yet whenever I click on a post that doesn't have a "brand" selected, the page it shows is just the category page rather than post.
I'm going to play around with it more but thought I'd post to see if anyone had suggestions.
Thanks again so much for the links/help!
Member (joined March 2012) Likes (0)
I'm sorry, in my comment/example above, when I referenced "Label" I meant "Brand". **
Also, it seems this plugin would assist the functionality of what I'm looking to achieve, although I think each structure in the examples he shows is prefixed with a static word, which in my case is not what I'm looking for. Still wanted to post as it could be food-for-thought for the next CustomPress update:
http://www.youtube.com/watch?v=0JK2baB2ck8
I really appreciate the help thus far and hope someone may have suggestions. Losing sleep over this; the needed permalink structure is vital in my case for SEO reasons and I'm unable to launch until I can figure this out :/
Thanks again!
-pgt
Support Kangaroo (joined March 2011) Likes (0)
Greetings pgt,
Thank you for all of your feedback, it is greatly appreciated.
I am going to see if I can get the lead developer in here with his invaluable input plus add this ticket to the feature requests so that possibly this may become available in Custom Press as a future option.
Though this may take longer then a normal ticket, I will see if I can get developer input asap.
Cheers, Joe
Member (joined March 2012) Likes (0)
thank you
Become a member