Get a category's subcategories

Use get_categories( $args ), where $args can be a string or an associative array like below:

$args = [
	'type'                     => 'post',
	'child_of'                 => 0,        // term or category id of parent
	'parent'                   => '',
	'orderby'                  => 'name',
	'order'                    => 'ASC',
	'hide_empty'               => 1,
	'hierarchical'             => 1,
	'exclude'                  => '',
	'include'                  => '',
	'number'                   => '',
	'taxonomy'                 => 'category',
	'pad_counts'               => false 


$subcats = get_categories(['child_of'=>get_category_by_slug('wordpress')->term_id, 'hide_empty'=>false]);
/* Returns an array (of objects) of said subcategory with the following fields:

// A for-each loop is always used when calling this function
foreach ($subcats as $subcat) {
  echo $subcat->term_id; // or whatever field it is you're interested in   

Get a category's link/URL

get_category_link( $category_id )
//-> String URL

Get the data of any category

get_term_by( $field, $value, $taxonomy, $output, $filter )

Will return false if $taxonomy does not exist or term was not found; otherwise, it returns an object or array of fields specified in the $output parameter.

Fields returned are:

  • term_id
  • name
  • slug
  • term_group
  • term_taxonomy_id
  • taxonomy
  • description
  • parent
  • count

A notice about string vs integer confusion. Field values, including term_id are returned in string format! So before you use these field values further, you must typecast numeric values (which is of string type) to actual integers, otherwise WordPress gets confused and will not return the proper value.

Get the category ID of the current/active page

// It's a global WP variable

Get the category ID of any category on any page

get_cat_ID('Category Name')