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
1166      $key = md5( serialize( compact(array_keys($defaults)) ) . serialize( $taxonomies ) . $filter_key );
1167      $last_changed = wp_cache_get('last_changed', 'terms');
1168      if ( !$last_changed ) {
1169           $last_changed = time();
1170           wp_cache_set('last_changed', $last_changed, 'terms');
1171      }
1172      $cache_key = "get_terms:$key:$last_changed";
1173      $cache = wp_cache_get( $cache_key, 'terms' );
1174      if ( false !== $cache ) {
1175           $cache = apply_filters('get_terms', $cache, $taxonomies, $args);
1176           return $cache;
1177      }
1178
1179      $_orderby = strtolower($orderby);
1180      if ( 'count' == $_orderby )
1181           $orderby = 'tt.count';
1182      else if ( 'name' == $_orderby )
1183           $orderby = 't.name';
1184      else if ( 'slug' == $_orderby )
 
Line Code
1315      }
1316
1317      $terms = $wpdb->get_results($query);
1318      if ( 'all' == $fields ) {
1319           update_term_cache($terms);
1320      }
1321
1322      if ( empty($terms) ) {
1323           wp_cache_add( $cache_key, array(), 'terms', 86400 ); // one day
1324           $terms = apply_filters('get_terms', array(), $taxonomies, $args);
1325           return $terms;
1326      }
1327
1328      if ( $child_of ) {
1329           $children = _get_term_hierarchy($taxonomies[0]);
1330           if ( ! empty($children) )
1331                $terms = & _get_term_children($child_of, $terms, $taxonomies[0]);
1332      }
1333
 
Line Code
1367           $terms = $_terms;
1368      }
1369
1370      if ( 0 < $number && intval(@count($terms)) > $number ) {
1371           $terms = array_slice($terms, $offset, $number);
1372      }
1373
1374      wp_cache_add( $cache_key, $terms, 'terms', 86400 ); // one day
1375
1376      $terms = apply_filters('get_terms', $terms, $taxonomies, $args);
1377      return $terms;
1378 }
1379
1380 /**
1381  * Check if Term exists.
1382  *
1383  * Returns the index of a defined term, or 0 (false) if the term doesn't exist.
1384  *
1385  * Formerly is_term(), introduced in 2.3.0.