26
26
function get_categories( $args = '' ) {
27
27
$defaults = array( 'taxonomy' => 'category' );
28
$args = wp_parse_args( $args, $defaults );
28
$args = wp_parse_args( $args, $defaults );
30
30
$taxonomy = $args['taxonomy'];
40
40
$taxonomy = apply_filters( 'get_categories_taxonomy', $taxonomy, $args );
43
if ( isset($args['type']) && 'link' == $args['type'] ) {
44
_deprecated_argument( __FUNCTION__, '3.0.0',
43
if ( isset( $args['type'] ) && 'link' == $args['type'] ) {
45
47
/* translators: 1: "type => link", 2: "taxonomy => link_category" */
46
sprintf( __( '%1$s is deprecated. Use %2$s instead.' ),
49
__( '%1$s is deprecated. Use %2$s instead.' ),
47
50
'<code>type => link</code>',
48
51
'<code>taxonomy => link_category</code>'
91
94
function get_category( $category, $output = OBJECT, $filter = 'raw' ) {
92
95
$category = get_term( $category, 'category', $output, $filter );
94
if ( is_wp_error( $category ) )
97
if ( is_wp_error( $category ) ) {
97
101
_make_cat_compat( $category );
120
124
* @return WP_Term|array|WP_Error|null Type is based on $output value.
122
126
function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) {
123
$category_path = rawurlencode( urldecode( $category_path ) );
124
$category_path = str_replace( '%2F', '/', $category_path );
125
$category_path = str_replace( '%20', ' ', $category_path );
127
$category_path = rawurlencode( urldecode( $category_path ) );
128
$category_path = str_replace( '%2F', '/', $category_path );
129
$category_path = str_replace( '%20', ' ', $category_path );
126
130
$category_paths = '/' . trim( $category_path, '/' );
127
$leaf_path = sanitize_title( basename( $category_paths ) );
131
$leaf_path = sanitize_title( basename( $category_paths ) );
128
132
$category_paths = explode( '/', $category_paths );
130
134
foreach ( (array) $category_paths as $pathdir ) {
131
135
$full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir );
133
$categories = get_terms( 'category', array('get' => 'all', 'slug' => $leaf_path) );
137
$categories = get_terms(
141
'slug' => $leaf_path,
135
145
if ( empty( $categories ) ) {
139
149
foreach ( $categories as $category ) {
140
$path = '/' . $leaf_path;
150
$path = '/' . $leaf_path;
141
151
$curcategory = $category;
142
152
while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) {
143
153
$curcategory = get_term( $curcategory->parent, 'category' );
170
180
* @param string $slug The category slug.
171
181
* @return object Category data object
173
function get_category_by_slug( $slug ) {
183
function get_category_by_slug( $slug ) {
174
184
$category = get_term_by( 'slug', $slug, 'category' );
176
186
_make_cat_compat( $category );
178
189
return $category;
202
214
* @return string Category name, or an empty string if category doesn't exist.
204
216
function get_cat_name( $cat_id ) {
205
$cat_id = (int) $cat_id;
217
$cat_id = (int) $cat_id;
206
218
$category = get_term( $cat_id, 'category' );
207
if ( ! $category || is_wp_error( $category ) )
219
if ( ! $category || is_wp_error( $category ) ) {
209
222
return $category->name;
262
275
* @see get_terms() For list of arguments to pass.
264
277
* @param string|array $args Tag arguments to use when retrieving tags.
265
* @return array List of tags.
278
* @return WP_Term[]|int $tags Array of 'post_tag' term objects, or a count thereof.
267
280
function get_tags( $args = '' ) {
268
281
$tags = get_terms( 'post_tag', $args );
280
* @param array $tags Array of 'post_tag' term objects.
281
* @param array $args An array of arguments. @see get_terms()
293
* @param WP_Term[]|int $tags Array of 'post_tag' term objects, or a count thereof.
294
* @param array $args An array of arguments. @see get_terms()
283
296
$tags = apply_filters( 'get_tags', $tags, $args );
344
357
function _make_cat_compat( &$category ) {
345
358
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
346
$category->cat_ID = $category->term_id;
347
$category->category_count = $category->count;
359
$category->cat_ID = $category->term_id;
360
$category->category_count = $category->count;
348
361
$category->category_description = $category->description;
349
$category->cat_name = $category->name;
350
$category->category_nicename = $category->slug;
351
$category->category_parent = $category->parent;
362
$category->cat_name = $category->name;
363
$category->category_nicename = $category->slug;
364
$category->category_parent = $category->parent;
352
365
} elseif ( is_array( $category ) && isset( $category['term_id'] ) ) {
353
$category['cat_ID'] = &$category['term_id'];
354
$category['category_count'] = &$category['count'];
366
$category['cat_ID'] = &$category['term_id'];
367
$category['category_count'] = &$category['count'];
355
368
$category['category_description'] = &$category['description'];
356
$category['cat_name'] = &$category['name'];
357
$category['category_nicename'] = &$category['slug'];
358
$category['category_parent'] = &$category['parent'];
369
$category['cat_name'] = &$category['name'];
370
$category['category_nicename'] = &$category['slug'];
371
$category['category_parent'] = &$category['parent'];