Hide specific taxonomies from a taxonomy list using ‘get_object_taxonomies’

Try this:

<?php
$object="post";
$output="objects";
$taxonomies = get_object_taxonomies( $object, $output );
$exclude = array( 'post_tag', 'post_format' );

if ( $taxonomies ) {

    foreach ( $taxonomies  as $taxonomy ) {

        if( in_array( $taxonomy->name, $exclude ) ) {
            continue;
        }

        $terms = get_terms( array(
            'taxonomy' => $taxonomy->name,
            'hide_empty' => true,
        ) );

        if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {

            echo '<h3>' . $taxonomy->label . '</h3>';   

            $term_list="<ul class="term-list">";

            foreach ( $terms as $term ) {
                $term_list .= '<li><a href="' . esc_url( get_term_link( $term ) ) . '" >' . $term->name . '</a></li>';          
            }

            $term_list .= '</ul>';

            echo $term_list;
        }

    }

}
?>

For this example I set up some parameters:

  • Post type we’re searching on: $object="post";
  • Taxonomies we want to exclude: $exclude = array( 'post_tag', 'post_format' );

Then we get all associated taxonomies and loop through them. While we loop through them, we check each taxonomy against our exclude array and skip it if applicable.

Then we grab all the terms from each taxonomy and build list of links.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)