Function: get_category_by_path

get_category_by_path( string $category_path, boolean $full_match, string $output )

Retrieve category based on URL containing the category slug.

Shortcut: gcbp

You can use above key combination to trigger the associated snippet for this function in the WordPress Snippets for Visual Studio Code extension. You can also use this shortcut to search for this function on this website.

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.


Name Type(s) Default Value Description
$category_path string

URL containing category slugs.

$full_match boolean true

Optional. Whether full path should be matched.

$output string OBJECT

Optional. The required return type. One of OBJECT, ARRAY_A, or ARRAY_N, which correspond to a WP_Term object, an associative array, or a numeric array, respectively. Default OBJECT.


WP_Term | array | WP_Error | null

Type is based on $output value.

WordPress Developer Newsletter

Stay informed of new chapter releases, important WordPress API updates and more.