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