I needed something like this for a client site, they wanted to add tags to all their products, but I didn’t want them just making up new tags, I wanted to give them a list of tags to start with.
vancoder’s answer provided the key I needed to get this done: the ‘hide_empty’ attribute.
What makes the code in the original question not work is it’s incomplete. Because you are overriding a WP function, you need to replace the entire function with your custom version, which must handle all the functionality of the original. The original function is found in wp-admin/includes/ajax-actions.php (line 836 in version 4.3) so that is copied and modified to create the overriding function:
add_action( 'wp_ajax_get-tagcloud', 'ti_theme_tag_cloud', 1);
function ti_theme_tag_cloud()
{
if ( ! isset( $_POST['tax'] ) ) {
wp_die( 0 );
}
$taxonomy = sanitize_key( $_POST['tax'] );
$tax = get_taxonomy( $taxonomy );
if ( ! $tax ) {
wp_die( 0 );
}
if ( ! current_user_can( $tax->cap->assign_terms ) ) {
wp_die( -1 );
}
$term_params = array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' );
switch ($taxonomy) {
case 'product_tag':
$term_params['hide_empty'] = false;
break;
}
$tags = get_terms( $taxonomy, $term_params );
if ( empty( $tags ) )
wp_die( $tax->labels->not_found );
if ( is_wp_error( $tags ) )
wp_die( $tags->get_error_message() );
foreach ( $tags as $key => $tag ) {
$tags[ $key ]->link = '#';
$tags[ $key ]->id = $tag->term_id;
}
// We need raw tag names here, so don't filter the output
$return = wp_generate_tag_cloud( $tags, array('filter' => 0) );
if ( empty($return) )
wp_die( 0 );
echo $return;
wp_die();
}
This overriding function adds an opportunity to change the tag cloud configuration based on the incoming taxonomy without affecting other taxonomies.
As an added refinement, I changed one of the labels in the ‘product_tag’ taxonomy:
'choose_from_most_used' => 'Choose Tags',
So that the user knows they are just getting a list of all the tags.