Title: get_category_by_slug
Published: April 25, 2014
Last modified: May 20, 2026

---

# get_category_by_slug( string $slug ): object|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#wp--skip-link--target)

Retrieves a category object by category slug.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#parameters)󠁿

 `$slug`stringrequired

The category slug.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#return)󠁿

 object|false Category data object on success, false if not found.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#more-information)󠁿

Same is achieved by:
 `get_term_by('slug', $slug, 'category');`

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#source)󠁿

    ```php
    function get_category_by_slug( $slug ) {
    	$category = get_term_by( 'slug', $slug, 'category' );

    	if ( $category ) {
    		_make_cat_compat( $category );
    	}

    	return $category;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/category.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/category.php#L189)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/category.php#L189-L197)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#related)󠁿

| Uses | Description | 
| [_make_cat_compat()](https://developer.wordpress.org/reference/functions/_make_cat_compat/)`wp-includes/category.php` |

Updates category structure to old pre-2.3 from new taxonomy structure.

  | 
| [get_term_by()](https://developer.wordpress.org/reference/functions/get_term_by/)`wp-includes/taxonomy.php` |

Gets all term data from database by term field and data.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#comment-content-1240)
 2.    [Ivan Shulev](https://profiles.wordpress.org/ishulev/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_category_by_slug/#comment-1240)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%23comment-1240)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%23comment-1240)
 4.  Returns **false** if not found
 5.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%3Freplytocom%3D1240%23feedback-editor-1240)
 6.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#comment-content-1241)
 7.    [Ivan Shulev](https://profiles.wordpress.org/ishulev/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/get_category_by_slug/#comment-1241)
 8.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%23comment-1241)
     Vote results for this note: 4[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%23comment-1241)
 9.  **Example**
 10.     ```php
         $idObj = get_category_by_slug( 'category-slug' );
     
         if ( $idObj instanceof WP_Term ) {
         	$id = $idObj->term_id;
         }
         ```
     
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%3Freplytocom%3D1241%23feedback-editor-1241)
 12.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/get_category_by_slug/?output_format=md#comment-content-3920)
 13.   [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/get_category_by_slug/#comment-3920)
 14. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%23comment-3920)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%23comment-3920)
 15. Example migrated from Codex:
 16.     ```php
         <?php 
            $idObj = get_category_by_slug('category-slug'); 
            $id = $idObj->term_id;
         ?>
         ```
     
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F%3Freplytocom%3D3920%23feedback-editor-3920)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_category_by_slug%2F)
before being able to contribute a note or feedback.