2 /** |
2 /** |
3 * WordPress Category API |
3 * WordPress Category API |
4 * |
4 * |
5 * @package WordPress |
5 * @package WordPress |
6 */ |
6 */ |
7 |
|
8 /** |
|
9 * Retrieves all category IDs. |
|
10 * |
|
11 * @since 2.0.0 |
|
12 * @link http://codex.wordpress.org/Function_Reference/get_all_category_ids |
|
13 * |
|
14 * @return object List of all of the category IDs. |
|
15 */ |
|
16 function get_all_category_ids() { |
|
17 if ( ! $cat_ids = wp_cache_get( 'all_category_ids', 'category' ) ) { |
|
18 $cat_ids = get_terms( 'category', array('fields' => 'ids', 'get' => 'all') ); |
|
19 wp_cache_add( 'all_category_ids', $cat_ids, 'category' ); |
|
20 } |
|
21 |
|
22 return $cat_ids; |
|
23 } |
|
24 |
7 |
25 /** |
8 /** |
26 * Retrieve list of category objects. |
9 * Retrieve list of category objects. |
27 * |
10 * |
28 * If you change the type to 'link' in the arguments, then the link categories |
11 * If you change the type to 'link' in the arguments, then the link categories |
29 * will be returned instead. Also all categories will be updated to be backwards |
12 * will be returned instead. Also all categories will be updated to be backwards |
30 * compatible with pre-2.3 plugins and themes. |
13 * compatible with pre-2.3 plugins and themes. |
31 * |
14 * |
32 * @since 2.1.0 |
15 * @since 2.1.0 |
33 * @see get_terms() Type of arguments that can be changed. |
16 * @see get_terms() Type of arguments that can be changed. |
34 * @link http://codex.wordpress.org/Function_Reference/get_categories |
17 * @link https://codex.wordpress.org/Function_Reference/get_categories |
35 * |
18 * |
36 * @param string|array $args Optional. Change the defaults retrieving categories. |
19 * @param string|array $args Optional. Change the defaults retrieving categories. |
37 * @return array List of categories. |
20 * @return array List of categories. |
38 */ |
21 */ |
39 function get_categories( $args = '' ) { |
22 function get_categories( $args = '' ) { |
40 $defaults = array( 'taxonomy' => 'category' ); |
23 $defaults = array( 'taxonomy' => 'category' ); |
41 $args = wp_parse_args( $args, $defaults ); |
24 $args = wp_parse_args( $args, $defaults ); |
42 |
25 |
43 $taxonomy = $args['taxonomy']; |
26 $taxonomy = $args['taxonomy']; |
|
27 |
44 /** |
28 /** |
45 * Filter the taxonomy used to retrieve terms when calling get_categories(). |
29 * Filter the taxonomy used to retrieve terms when calling {@see get_categories()}. |
46 * |
30 * |
47 * @since 2.7.0 |
31 * @since 2.7.0 |
48 * |
32 * |
49 * @param string $taxonomy Taxonomy to retrieve terms from. |
33 * @param string $taxonomy Taxonomy to retrieve terms from. |
50 * @param array $args An array of arguments. @see get_terms() |
34 * @param array $args An array of arguments. See {@see get_terms()}. |
51 */ |
35 */ |
52 $taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args ); |
36 $taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args ); |
53 |
37 |
54 // Back compat |
38 // Back compat |
55 if ( isset($args['type']) && 'link' == $args['type'] ) { |
39 if ( isset($args['type']) && 'link' == $args['type'] ) { |
78 * filters and finally sanitized based on the $filter parameter value. |
62 * filters and finally sanitized based on the $filter parameter value. |
79 * |
63 * |
80 * The category will converted to maintain backwards compatibility. |
64 * The category will converted to maintain backwards compatibility. |
81 * |
65 * |
82 * @since 1.5.1 |
66 * @since 1.5.1 |
83 * @uses get_term() Used to get the category data from the taxonomy. |
|
84 * |
67 * |
85 * @param int|object $category Category ID or Category row object |
68 * @param int|object $category Category ID or Category row object |
86 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N |
69 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N |
87 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. |
70 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. |
88 * @return mixed Category data in type defined by $output parameter. |
71 * @return object|array|WP_Error|null Category data in type defined by $output parameter. WP_Error if $category is empty, null if it does not exist. |
89 */ |
72 */ |
90 function get_category( $category, $output = OBJECT, $filter = 'raw' ) { |
73 function get_category( $category, $output = OBJECT, $filter = 'raw' ) { |
91 $category = get_term( $category, 'category', $output, $filter ); |
74 $category = get_term( $category, 'category', $output, $filter ); |
|
75 |
92 if ( is_wp_error( $category ) ) |
76 if ( is_wp_error( $category ) ) |
93 return $category; |
77 return $category; |
94 |
78 |
95 _make_cat_compat( $category ); |
79 _make_cat_compat( $category ); |
96 |
80 |
238 |
221 |
239 /** |
222 /** |
240 * Sanitizes data in single category key field. |
223 * Sanitizes data in single category key field. |
241 * |
224 * |
242 * @since 2.3.0 |
225 * @since 2.3.0 |
243 * @uses sanitize_term_field() See function for more details. |
|
244 * |
226 * |
245 * @param string $field Category key to sanitize |
227 * @param string $field Category key to sanitize |
246 * @param mixed $value Category value to sanitize |
228 * @param mixed $value Category value to sanitize |
247 * @param int $cat_id Category ID |
229 * @param int $cat_id Category ID |
248 * @param string $context What filter to use, 'raw', 'display', etc. |
230 * @param string $context What filter to use, 'raw', 'display', etc. |
257 /** |
239 /** |
258 * Retrieves all post tags. |
240 * Retrieves all post tags. |
259 * |
241 * |
260 * @since 2.3.0 |
242 * @since 2.3.0 |
261 * @see get_terms() For list of arguments to pass. |
243 * @see get_terms() For list of arguments to pass. |
262 * @uses apply_filters() Calls 'get_tags' hook on array of tags and with $args. |
|
263 * |
244 * |
264 * @param string|array $args Tag arguments to use when retrieving tags. |
245 * @param string|array $args Tag arguments to use when retrieving tags. |
265 * @return array List of tags. |
246 * @return array List of tags. |
266 */ |
247 */ |
267 function get_tags( $args = '' ) { |
248 function get_tags( $args = '' ) { |
299 * @since 2.3.0 |
280 * @since 2.3.0 |
300 * |
281 * |
301 * @param int|object $tag |
282 * @param int|object $tag |
302 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N |
283 * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N |
303 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. |
284 * @param string $filter Optional. Default is raw or no WordPress defined filter will applied. |
304 * @return object|array Return type based on $output value. |
285 * @return object|array|WP_Error|null Tag data in type defined by $output parameter. WP_Error if $tag is empty, null if it does not exist. |
305 */ |
286 */ |
306 function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) { |
287 function get_tag( $tag, $output = OBJECT, $filter = 'raw' ) { |
307 return get_term( $tag, 'post_tag', $output, $filter ); |
288 return get_term( $tag, 'post_tag', $output, $filter ); |
308 } |
289 } |
309 |
290 |