Title: wp_ajax_get_tagcloud
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_ajax_get_tagcloud()

## In this article

 * [Source](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#wp--skip-link--target)

Handles getting a tagcloud via AJAX.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#source)󠁿

    ```php
    function wp_ajax_get_tagcloud() {
    	if ( ! isset( $_POST['tax'] ) ) {
    		wp_die( 0 );
    	}

    	$taxonomy        = sanitize_key( $_POST['tax'] );
    	$taxonomy_object = get_taxonomy( $taxonomy );

    	if ( ! $taxonomy_object ) {
    		wp_die( 0 );
    	}

    	if ( ! current_user_can( $taxonomy_object->cap->assign_terms ) ) {
    		wp_die( -1 );
    	}

    	$tags = get_terms(
    		array(
    			'taxonomy' => $taxonomy,
    			'number'   => 45,
    			'orderby'  => 'count',
    			'order'    => 'DESC',
    		)
    	);

    	if ( empty( $tags ) ) {
    		wp_die( $taxonomy_object->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,
    			'format' => 'list',
    		)
    	);

    	if ( empty( $return ) ) {
    		wp_die( 0 );
    	}

    	echo $return;
    	wp_die();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/ajax-actions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/ajax-actions.php#L1183)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/ajax-actions.php#L1183-L1236)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_generate_tag_cloud()](https://developer.wordpress.org/reference/functions/wp_generate_tag_cloud/)`wp-includes/category-template.php` |

Generates a tag cloud (heatmap) from provided data.

  | 
| [get_terms()](https://developer.wordpress.org/reference/functions/get_terms/)`wp-includes/taxonomy.php` |

Retrieves the terms in a given taxonomy or list of taxonomies.

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [sanitize_key()](https://developer.wordpress.org/reference/functions/sanitize_key/)`wp-includes/formatting.php` |

Sanitizes a string key.

  | 
| [wp_die()](https://developer.wordpress.org/reference/functions/wp_die/)`wp-includes/functions.php` |

Kills WordPress execution and displays HTML page with an error message.

  | 
| [get_taxonomy()](https://developer.wordpress.org/reference/functions/get_taxonomy/)`wp-includes/taxonomy.php` |

Retrieves the taxonomy object of $taxonomy.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 5 more](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_ajax_get_tagcloud/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_ajax_get_tagcloud%2F)
before being able to contribute a note or feedback.