ccurtin
5/28/2015 - 8:46 PM

Include taxonomy category in the slug: pretty-permalink. EX: www.website.com/portfolio/YOUR-CATEGORY/project-one

Include taxonomy category in the slug: pretty-permalink.

EX: www.website.com/portfolio/YOUR-CATEGORY/project-one

<?php

// In the $args variable:
// For registering custom-post-type
     array('rewrite' => array('slug' => 'portfolio/%portfolio-media-type%','with_front' => false));
// For registering custom-post-type taxonomy
     array('rewrite' =>  array('slug' => 'portfolio' ));

?>


<?php
// Don't forget to update permalinks after implementing
add_filter('post_link', 'portfolio_category', 1, 3);
add_filter('post_type_link', 'portfolio_category', 1, 3);

function portfolio_category($permalink, $post_id, $leavename) {
	//con %brand% catturo il rewrite del Custom Post Type
    if (strpos($permalink, '%portfolio-media-type%') === FALSE) return $permalink;
        // Get post
        $post = get_post($post_id);
        if (!$post) return $permalink;

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

    return str_replace('%portfolio-media-type%', $taxonomy_slug, $permalink);
}

?>