get_category_feed_link

Definition:
function get_category_feed_link($cat_id, $feed = '') {}

Retrieve the feed link for a category.
Returns a link to the feed for all posts in a given category. A specific feed can be requested or left blank to get the default feed.

Parameters

  • int $cat_id: ID of a category.
  • string $feed: Optional. Feed type.

Return values

returns:Link to the feed for the category specified by $cat_id.

Source code

function get_category_feed_link($cat_id, $feed = '') {

	return get_term_feed_link($cat_id, 'category', $feed);

}

1250

get_category_children

Definition:
function get_category_children( $id, $before = '/', $after = '', $visited = array() {}

Retrieve category children list separated before and after the term IDs.

Parameters

  • int $id: Category ID to retrieve children.
  • string $before: Optional. Prepend before category term ID.
  • string $after: Optional, default is empty string. Append after category term ID.
  • array $visited: Optional. Category Term IDs that have already been added.

Source code

function get_category_children( $id, $before = '/', $after = '', $visited = array() ) {

	_deprecated_function( __FUNCTION__, '2.8', 'get_term_children()' );

	if ( 0 == $id )

		return '';



	$chain = '';

	/** TODO: consult hierarchy */

	$cat_ids = get_all_category_ids();

	foreach ( (array) $cat_ids as $cat_id ) {

		if ( $cat_id == $id )

			continue;



		$category = get_category( $cat_id );

		if ( is_wp_error( $category ) )

			return $category;

		if ( $category->parent == $id && !in_array( $category->term_id, $visited ) ) {

			$visited[] = $category->term_id;

			$chain .= $before.$category->term_id.$after;

			$chain .= get_category_children( $category->term_id, $before, $after );

		}

	}

	return $chain;

}

1248

get_category_by_slug

Definition:
function get_category_by_slug( $slug ) {}

Retrieve category object by category slug.

Parameters

  • string $slug: The category slug.

Return values

returns:data object

Source code

function get_category_by_slug( $slug  ) {

	$category = get_term_by( 'slug', $slug, 'category' );

	if ( $category )

		_make_cat_compat( $category );



	return $category;

}

1246

get_category_by_path

Definition:
function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) {}

Retrieve category based on URL containing the category slug.
Breaks the $category_path parameter up to get the category slug.

Parameters

  • string $category_path: URL containing category slugs.
  • bool $full_match: Optional. Whether full path should be matched.
  • string $output: Optional. Constant OBJECT, ARRAY_A, or ARRAY_N

Return values

returns:Null on failure. Type is based on $output value.

Source code

function get_category_by_path( $category_path, $full_match = true, $output = OBJECT ) {

	$category_path = rawurlencode( urldecode( $category_path ) );

	$category_path = str_replace( '%2F', '/', $category_path );

	$category_path = str_replace( '%20', ' ', $category_path );

	$category_paths = '/' . trim( $category_path, '/' );

	$leaf_path  = sanitize_title( basename( $category_paths ) );

	$category_paths = explode( '/', $category_paths );

	$full_path = '';

	foreach ( (array) $category_paths as $pathdir )

		$full_path .= ( $pathdir != '' ? '/' : '' ) . sanitize_title( $pathdir );



	$categories = get_terms( 'category', array('get' => 'all', 'slug' => $leaf_path) );



	if ( empty( $categories ) )

		return null;



	foreach ( $categories as $category ) {

		$path = '/' . $leaf_path;

		$curcategory = $category;

		while ( ( $curcategory->parent != 0 ) && ( $curcategory->parent != $curcategory->term_id ) ) {

			$curcategory = get_term( $curcategory->parent, 'category' );

			if ( is_wp_error( $curcategory ) )

				return $curcategory;

			$path = '/' . $curcategory->slug . $path;

		}



		if ( $path == $full_path )

			return get_category( $category->term_id, $output );

	}



	// If full matching is not required, return the first cat that matches the leaf.

	if ( ! $full_match )

		return get_category( $categories[0]->term_id, $output );



	return null;

}

1244

get_category

Definition:
function &get_category( $category, $output = OBJECT, $filter = 'raw' ) {}

Retrieves category data given a category ID or category object.
If you pass the $category parameter an object, which is assumed to be the category row object retrieved the database. It will cache the category data.

Parameters

  • int|object $category: Category ID or Category row object
  • string $output: Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
  • string $filter: Optional. Default is raw or no WordPress defined filter will applied.

Return values

returns:Category data in type defined by $output parameter.

Source code

function &get_category( $category, $output = OBJECT, $filter = 'raw' ) {

	$category = get_term( $category, 'category', $output, $filter );

	if ( is_wp_error( $category ) )

		return $category;



	_make_cat_compat( $category );



	return $category;

}

1242