custom taxonomies on permalink

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?

2 Answers
2

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.

Leave a Comment