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.

Re: Custom post types, taxonomies, and permalinks by @TheDeadMechanic The solution above works perfectly, and rewrite is great, but can you advise on how to rewrite for more than one custom post type with its own taxonomy? the code below works for taxonomy product cat under products, but adding another CPT with taxonomy gives 404 as it not included below, how can the code below be amended to cater for more than one CPT and taxonomy?

function filter_post_type_link($link, $post)

{ if ($post->post_type != 'product_listing') return $link;

if ($cats = get_the_terms($post->ID, 'product_cat'))
    $link = str_replace('%product_cat%', array_pop($cats)->slug, $link);
return $link;

} add_filter('post_type_link', 'filter_post_type_link', 10, 2);

thanks in advance

share|improve this question
    
I am having the same struggle, getting 404 error with more than one rewrite of custom taxonomies or pst types -.- Hope someone can help. –  OriginalEXE Jun 22 '12 at 15:30

1 Answer 1

Assuming the code snippet provided works then extending the conditional statement like so will help you,

function filter_post_type_link($link, $post)
{
    if ($post->post_type = 'custom_post_type_1') {

        if ($cats = get_the_terms($post->ID, 'custom_cat_1'))

             $link = str_replace('%custom_cat_1%', array_pop($cats)->slug, $link);

        return $link;

    } elseif ($post->post_type = 'custom_post_type_2') {

        if ($cats = get_the_terms($post->ID, 'custom_cat_2'))

             $link = str_replace('%custom_cat_2%', array_pop($cats)->slug, $link);

        return $link;

    } else {

        return $link;

    }

}

add_filter('post_type_link', 'filter_post_type_link', 10, 2);
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.