-1

I have my permalink set to %postname%/%location%/%course% I want this permalink %location%/%course%/%postname% but due to this I get 404 on every page but not on posts, I decided to put this permalink %postname%/%location%/%course%/%postname% but I need to strip the starting postname, in such a way I ll get no 404 pages and google will also index my site with this permalink /%location%/%course%/%postname% without any 404

how to do this????

This is my code, for displaying custom taxonomies on permalinks

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


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

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

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

        return str_replace('%location%', $taxonomy_slug, $permalink);
    }
4
  • Can you post the code you're registering those taxonomies with? Assuming they're custom taxonomies that is. Jan 11, 2011 at 15:30
  • I'm not trying to be snarky, but asking for you to please consider using capitalization where appropriate ("i" especially) and periods at the end of sentences. It's very hard to read your questions otherwise. Thanks in advance for helping those who aim to help you. Jan 11, 2011 at 17:41
  • sorry for bad english, i ll rewrite my answer Jan 12, 2011 at 4:57
  • @sanchothefat I am using GDCPT plugin for custom taxonomies, and it works fine with the posts, just to display the terms of custom taxonomies I am using a piece of code, check my original answer Jan 12, 2011 at 5:11

1 Answer 1

1

Apologies that this doesn't directly answer your question but If I were you I would use the following structure:

/%post_id%/%location%/%course%/%postname%

Using the id should help to speed up the page load as it reduces the amount of processing that WP needs to do to select the correct page and you still get a nice enough url.

1
  • I want my URL structure to start with Location, if I am starting it with Location, then all of my Pages are getting 404 error, only posts are opening, do you have any suggestions why is it happening so? Jan 13, 2011 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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