get_categories

Retrieve list of category objects.

Description

(array) get_categories( (string) $args = '' ); 

If you change the type to link in the arguments, then the link categories will be returned instead. Also all categories will be updated to be backward compatible with pre-2.3 plugins and themes.

Returns (array)

List of categories.

Parameters (1)

0. $args — Optional. (string) => ''
Arguments to retrieve categories. See get_terms() for additional options.

Options

    ;        


    Usage

    1. if ( !function_exists( 'get_categories' ) ) { 
    2. require_once ABSPATH . WPINC . '/category.php'; 
    3.  
    4. // Optional. Arguments to retrieve categories. See get_terms() for additional options. 
    5. $args = ''; 
    6.  
    7. // NOTICE! Understand what this does before running. 
    8. $result = get_categories($args); 
    9.  

    Defined (1)

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

    /wp-includes/category.php  
    1. function get_categories( $args = '' ) { 
    2. $defaults = array( 'taxonomy' => 'category' ); 
    3. $args = wp_parse_args( $args, $defaults ); 
    4.  
    5. $taxonomy = $args['taxonomy']; 
    6.  
    7. /** 
    8. * Filters the taxonomy used to retrieve terms when calling get_categories(). 
    9. * @since 2.7.0 
    10. * @param string $taxonomy Taxonomy to retrieve terms from. 
    11. * @param array $args An array of arguments. See get_terms(). 
    12. */ 
    13. $taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args ); 
    14.  
    15. // Back compat 
    16. if ( isset($args['type']) && 'link' == $args['type'] ) { 
    17. /** translators: 1: "type => link", 2: "taxonomy => link_category" alternative */ 
    18. _deprecated_argument( __FUNCTION__, '3.0.0',  
    19. sprintf( __( '%1$s is deprecated. Use %2$s instead.' ),  
    20. '<code>type => link</code>',  
    21. '<code>taxonomy => link_category</code>' 
    22. ); 
    23. $taxonomy = $args['taxonomy'] = 'link_category'; 
    24.  
    25. $categories = get_terms( $taxonomy, $args ); 
    26.  
    27. if ( is_wp_error( $categories ) ) { 
    28. $categories = array(); 
    29. } else { 
    30. $categories = (array) $categories; 
    31. foreach ( array_keys( $categories ) as $k ) { 
    32. _make_cat_compat( $categories[ $k ] ); 
    33.  
    34. return $categories;