Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

is it possible to bring custom taxonomies to permalink?

currently my permalink is looking something like this /%postname%/%category%

but i also want to add custom taxonomies to my permalink so it should look something like this

/%postname%/%category%/%location%/%mba_courses%

is this possible?

the solution to this answer i found, i googled and i found this code, which works perfetc for me

add_filter('post_link', 'mba_courses_permalink', 10, 3);
add_filter('post_type_link', 'mba_courses_permalink', 10, 3);

function mba_courses_permalink($permalink, $post_id, $leavename) {
    if (strpos($permalink, '%mba_courses%') === FALSE) return $permalink;

        // Get post
        $post = get_post($post_id);
        if (!$post) return $permalink;

        // Get taxonomy terms
        $terms = wp_get_object_terms($post->ID, 'mba_courses'); 
        if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
        else $taxonomy_slug = 'mba_courses';

    return str_replace('%mba_courses%', $taxonomy_slug, $permalink);
}

but now i have one more problem, when i google my website i get the old url structure link, when i click on that i get 404 error, where as the post is still inside the website, just the url has changed, so how can i make the old url to direct it to new url i mean if clicking on the old url and instead of redirecting to 404 page, can it redirect to the actual post where i have the new url?

is this possible?

share|improve this question
    
Supposedly this was going to be part of WordPress 3.1. However, it looks like it required some rewriting of how the entire permalink system works. I think the rewrite was done, but the upper exposing stuff was not. –  mtekk Dec 30 '10 at 1:45

2 Answers 2

up vote 0 down vote accepted

What you're looking for is a 301 redirect. I use two plugins to catch do this. One notify's me of 404 errors ( http://wordpress.org/extend/plugins/404-notifier/ ) and the other makes writing the 301 redirects easy ( http://wordpress.org/extend/plugins/simple-301-redirects/ ).

You could also write the 301 redirects in your .htaccess file and dig through the server logs to find the 404 notices.

Long term you just need to wait for Google to crawl the site and find the new link structure. If other people are linking to your site from other blogs you can try and get them to fix their links but it's unlikely that you'll be able to get many people to do that.

share|improve this answer
    
this will make me mad, cause i have 1000+ posts, and for each if i keep on writing the url, it will go crazy, is there any other way to make this, cause now my about us page is also not opening my permalink structure is : /%location%/%mba_courses%/%postname% where my location and mba_courses is custom taxonomy –  ntechi Dec 29 '10 at 12:29
    
Not that I'm aware of (though that doesn't mean there isn't). Permalinks are called that because they are supposed to be permanent. I've had to do the same things for a few thousand posts before and yes it does suck but it's the price of changing the permalink structure as you have done. –  curtismchale Dec 29 '10 at 12:39
    
You could also set the structure as you had it before and write custom permalinks for each post. wordpress.org/extend/plugins/custom-permalinks –  curtismchale Dec 29 '10 at 12:42
    
so it means there is no other solution rather then keep on editing each and every post url? –  ntechi Dec 29 '10 at 12:42
    
There might be but we'll have to wait and see when others offer solutions. –  curtismchale Dec 29 '10 at 12:51

http://wordpress.org/extend/plugins/custom-post-permalinks/ does that for custom posts, I'm sure you can easily extend it to support the 'post' post-type as well.

I've used it extensively on a couple of sites and it works great.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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