wp_ajax_get_tagcloud

Ajax handler for getting a tagcloud.

Description

wp_ajax_get_tagcloud(); 

Usage

  1. if ( !function_exists( 'wp_ajax_get_tagcloud' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_get_tagcloud(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_get_tagcloud() { 
  2. if ( ! isset( $_POST['tax'] ) ) { 
  3. wp_die( 0 ); 
  4.  
  5. $taxonomy = sanitize_key( $_POST['tax'] ); 
  6. $tax = get_taxonomy( $taxonomy ); 
  7. if ( ! $tax ) { 
  8. wp_die( 0 ); 
  9.  
  10. if ( ! current_user_can( $tax->cap->assign_terms ) ) { 
  11. wp_die( -1 ); 
  12.  
  13. $tags = get_terms( $taxonomy, array( 'number' => 45, 'orderby' => 'count', 'order' => 'DESC' ) ); 
  14.  
  15. if ( empty( $tags ) ) 
  16. wp_die( $tax->labels->not_found ); 
  17.  
  18. if ( is_wp_error( $tags ) ) 
  19. wp_die( $tags->get_error_message() ); 
  20.  
  21. foreach ( $tags as $key => $tag ) { 
  22. $tags[ $key ]->link = '#'; 
  23. $tags[ $key ]->id = $tag->term_id; 
  24.  
  25. // We need raw tag names here, so don't filter the output 
  26. $return = wp_generate_tag_cloud( $tags, array('filter' => 0) ); 
  27.  
  28. if ( empty($return) ) 
  29. wp_die( 0 ); 
  30.  
  31. echo $return; 
  32.  
  33. wp_die();