I've got a custom post type for which I wanted to modify the URL to show the name of the product and the brand name, (a taxonomy).
Here is my code
<blockquote>
add_filter('post_type_link', 'custom_post_link', 1, 3);
function custom_post_link( $post_link, $id = 0 )
{
$post = get_post($id);
if ( is_object($post) || $post->post_type == 'products' )
{
$terms = wp_get_object_terms($post->ID, 'brands');
if ($terms)
{
return $post_link . '-by-' . $terms[0]->slug . '.html';
}
}
else
{
return $post_link;
}
}</blockquote>
When I save my post, the permalink generates properly to
/products/name-of-my-product-by-brand.html and the URLs are shown correctly when called with the_permalink(). Just one problem, calling the URL return a 404. Is there a custom rewrite rule I need to put in place in addition to the filter.