How do I display a tag cloud with both post tags AND a custom taxonomy?

Using wp_tag_cloud(), how can I display a single tag cloud that incorporates both regular post tags and a custom taxonomy?

Related posts

Leave a Reply

1 comment

  1. The following is a slightly modified version of the wp_tag_cloud() function:

    function custom_wp_tag_cloud( $args = '' ) {
        $defaults = array(
            'smallest' => 8, 'largest' => 22, 'unit' => 'pt', 'number' => 45,
            'format' => 'flat', 'separator' => "n", 'orderby' => 'name', 'order' => 'ASC',
            'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
        );
        $args = wp_parse_args( $args, $defaults );
    
        $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
    
        if ( empty( $tags ) )
            return;
    
        foreach ( $tags as $key => $tag ) {
            if ( 'edit' == $args['link'] )
                $link = get_edit_tag_link( $tag->term_id, $tag->taxonomy );
            else
                $link = get_term_link( intval($tag->term_id), $tag->taxonomy );
            if ( is_wp_error( $link ) )
                return false;
    
            $tags[ $key ]->link = $link;
            $tags[ $key ]->id = $tag->term_id;
        }
    
        $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
    
        $return = apply_filters( 'wp_tag_cloud', $return, $args );
    
        if ( 'array' == $args['format'] || empty($args['echo']) )
            return $return;
    
        echo $return;
    }
    

    Use the taxonomy argument:

    $args = array(
       'taxonomy' => array( 'post_tag', 'custom_taxonomy' )
    );
    custom_wp_tag_cloud( $args );