Is it possible to show posts filtered by both taxonomies and categories? I.e. I have two categories: “News” and “Reviews” I have a custom taxonomy called ‘actor’.
Can I show all the posts filled in the “News” category and “Tom Hanks” actor? Or all the news related to “Russel Crowe”? Or all the reviews related to “Tom Cruise”?
Actually I have this permalink structure: http://myblog/actor/tom-hanks/
I'd like to have http://myblog/actor/tom-hanks/news/ http://myblog/actor/tom-hanks/reviews/
I know that with the default wordpress permalink structure this isn't possible. So I've tried to make a plugin but I haven't got the result.
This is the plugin:
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
add_filter('query_vars','wp_insertMyRewriteQueryVars');
add_filter('init','flushRules');
// Remember to flush_rules() when adding rules
function flushRules(){
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
// Adding a new rule
function wp_insertMyRewriteRules($rules)
{
global $wp_rewrite;
// add rewrite tokens
$actor_category = '%actor_category%';
$wp_rewrite->add_rewrite_tag($actor_category, '(.+?)', 'actor_category=');
$wp_rewrite->extra_permastructs = array ( '0' => '/actor/%actor%/%actor_category%', '1' => '0') + $wp_rewrite->extra_permastructs;
$keywords_structure = $wp_rewrite->root . "/%actor%/%actor_category%/";
$keywords_rewrite = $wp_rewrite->generate_rewrite_rules($keywords_structure, $ep_mask = EP_NONE, $page = false, $feed = false, $forcomments = false, $walks_dir = false);
$wp_rewrite->extra_rules_top = $keywords_rewrite + $wp_rewrite->extra_rules_top ;
return $wp_rewrite->extra_rules_top;
}
// Adding the id var so that WP recognizes it
function wp_insertMyRewriteQueryVars($vars)
{
$vars[] = "actor_category";
return $vars;
}