I Have posted this in several places but the wp forums take weeks sometimes to get responses.
I am trying to get my custom taxonomies to operate like post categories, with permalinks like
/post-type/tax-term/tax-term-child/tax-term-grandchild/post-name/
ive got a function hooked into post_type_links that gives my links this structure. here it is
add_filter('post_type_link', 'product_permalink', 10, 3);
function product_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%res_brands%') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'resbrands');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {
$term_count = count($terms);
$i=1;
if($term_count > 1){
foreach( $terms as $term ) {
if (!empty($term) && is_object($term)) $taxonomy_slug .= $term->slug;
if($i < $term_count) $taxonomy_slug .= '/';
$i++;
}
} else {
$taxonomy_slug = $terms[0]->slug;
}
}
//else $taxonomy_slug = 'not-rated';
return str_replace('%res_brands%', $taxonomy_slug, $permalink);
}
where my trouble lies is that the links lead to 404s due to the fact that %res_brands% could be parent/child/grandchild and it only recognizes 1 im assuiming, this is where i need help.
im using
global $wp_rewrite;
$wp_rewrite->add_rewrite_tag("%res_brands%", '([^/]+)', "resbrands=");
and assuming that i could just change the ([^/]+) to something that only recognizes the last /grandchild or /child if no grandchild. does it work like a preg_replace? can i echo out multiple values into an array exploding at the /? any ideas would be helpful. Thanks