Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get category by path


Retrieve category based on URL containing the category slug.

Breaks the $category_path parameter up to get the category slug.

Tries to find the child path and will return it. If it doesn't find a match, then it will return the first category matching slug, if $full_match, is set to false. If it does not, then it will return null.

It is also possible that it will return a WP_Error object on failure. Check for it when using this function.


<?php get_category_by_path$category_path$full_match$output ?>


(string) (required) URL containing category slugs.
Default: None
(boolean) (optional) Whether should match full path or not.
Default: true
(string) (optional) Constant OBJECT, ARRAY_A, or ARRAY_N
Default: OBJECT

Return Values

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


Default usage

$categ = get_category_by_path('uncategorized');
echo "Category ".$categ->name;


Change Log

Since: 2.1.0

Source File

get_category_by_path() is located in wp-includes/category.php.


See also index of Function Reference and index of Template Tags.