Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: get_terms

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 3 times in this file.

Line Code
1206      $key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key );
1207      $last_changed = wp_cache_get('last_changed', 'terms');
1208      if ( !$last_changed ) {
1209           $last_changed = time();
1210           wp_cache_set('last_changed', $last_changed, 'terms');
1211      }
1212      $cache_key = "get_terms:$key:$last_changed";
1213      $cache = wp_cache_get( $cache_key, 'terms' );
1214      if ( false !== $cache ) {
1215           $cache = apply_filters('get_terms', $cache, $taxonomies, $args);
1216           return $cache;
1217      }
1218
1219      $_orderby = strtolower($orderby);
1220      if ( 'count' == $_orderby )
1221           $orderby = 'tt.count';
1222      else if ( 'name' == $_orderby )
1223           $orderby = 't.name';
1224      else if ( 'slug' == $_orderby )
 
Line Code
1363      }
1364
1365      $terms = $wpdb->get_results($query);
1366      if ( 'all' == $fields ) {
1367           update_term_cache($terms);
1368      }
1369
1370      if ( empty($terms) ) {
1371           wp_cache_add( $cache_key, array(), 'terms', 86400 ); // one day
1372           $terms = apply_filters('get_terms', array(), $taxonomies, $args);
1373           return $terms;
1374      }
1375
1376      if ( $child_of ) {
1377           $children = _get_term_hierarchy($taxonomies[0]);
1378           if ( ! empty($children) )
1379                $terms = & _get_term_children($child_of, $terms, $taxonomies[0]);
1380      }
1381
 
Line Code
1415           $terms = $_terms;
1416      }
1417
1418      if ( 0 < $number && intval(@count($terms)) > $number ) {
1419           $terms = array_slice($terms, $offset, $number);
1420      }
1421
1422      wp_cache_add( $cache_key, $terms, 'terms', 86400 ); // one day
1423
1424      $terms = apply_filters('get_terms', $terms, $taxonomies, $args);
1425      return $terms;
1426 }
1427
1428 /**
1429  * Check if Term exists.
1430  *
1431  * Returns the index of a defined term, or 0 (false) if the term doesn't exist.
1432  *
1433  * Formerly is_term(), introduced in 2.3.0.