On a taxonomy archive it’s fairly straightforward, as you can get the current taxonomy with:
$term_object = get_queried_object();
$taxonomy = $term_object->taxonomy;
On a post type archive it’s a little bit more complicated as you first need to identify the current post type, and then retrieve the taxonomy/taxonomies attached to that post type:
$post_type_object = get_queried_object();
$taxonomies = get_object_taxonomies( $post_type_object->name );
if ( ! empty( $taxonomies ) ) {
$taxonomy = $taxonomies[0];
}
So you’ll need to combine these methods with a check for what you’re viewing to get the list of terms in either the current taxonomy or related to the current post type:
$taxonomy = null;
if ( is_tax() ) {
$term_object = get_queried_object();
$taxonomy = $term_object->taxonomy;
} elseif ( is_post_type_archive() ) {
$post_type_object = get_queried_object();
$taxonomies = get_object_taxonomies( $post_type_object->name );
$taxonomies = array_filter( $taxonomies, function( $taxonomy_name ) {
return get_taxonomy( $taxonomy_name )->public;
} );
if ( ! empty( $taxonomies ) ) {
$taxonomy = $taxonomies[0];
}
}
if ( $taxonomy ) {
wp_list_categories( array(
'show_option_all' => 'wszystkie',
'taxonomy' => $taxonomy,
'style' => 'none',
'separator' => '',
) );
}
EDIT: I have added this to the post type archive version of the code to filter out any non-public taxonomies attached to the post type:
$taxonomies = array_filter( $taxonomies, function( $taxonomy_name ) {
return get_taxonomy( $taxonomy_name )->public;
} );