wp get category by id
wp_get_category( int|object $category ), wp_get_category( string $category ) This function retrieves category data given a category ID or category object.
- The function wp_get_category() is used to retrieve category data based on the category ID or category object provided as the parameter.
- The parameter $category can be either an integer representing the category ID, or an object representing the category.
- If an integer is passed as the $category parameter, it represents the category ID.
- If an object is passed as the $category parameter, it represents the category object.
- The function returns the category data in the form of an object on success, and an array or empty string if the category is not found.
- The data returned includes the ID, name, slug, and other information associated with the category.
Example:
$category_id = 5;
$category_data = wp_get_category( $category_id );
In the example above, the variable $category_id is assigned the value 5 as the category ID. The function wp_get_category() is then called with $category_id passed as the parameter, and the returned category data is stored in the variable $category_data.