Right now I am outputting the related categories to the current displayed post type as shown below. I am using wp_list_categories
to list out the categories and it works just fine. The only issue is that this is being displayed on archive.php and not a single post, so the Taxonomies that are being listed link to their main taxonomy archive.
I would like to link to the taxonomy archive for the current post type ($type
) as well as include the query to display that specific taxonomy. Similar to linking to http://example.com?post_type=foo&custom_tax=bar
<? $type = get_post_type(); ?>
<?php
$customPostTaxonomies = get_object_taxonomies($type);
if(count($customPostTaxonomies) > 0)
{
echo '<h3>Browse By:</h3>';
foreach($customPostTaxonomies as $tax)
{
$args = array(
'orderby' => 'name',
'show_count' => 0,
'pad_counts' => 0,
'hierarchical' => 1,
'taxonomy' => $tax,
'title_li' => ''
);
$woah = get_taxonomy($tax);
echo '<ul>';
//var_dump($tax);
//var_dump($woah);
//print_r($woah);
echo '<h4>'.$woah->labels->name.'</h4>';
echo wp_list_categories( $args );
echo '</ul>';
}
}
?>`
wp_list_categories
usesget_term_link
to retrive the terms link.This function have a filter that you can use to change what is returned.
A problem is that you have to pass the current post type to the function that hooks into the filter, but a global variable should works for the scope.
Of course you have to remove filter after all
wp_list_categories
calls, for not interfere with nex class ofget_term_link
.So, in your
functions.php
put:Then change the code you posted like so: