WordPress Find Categories By Name

WordPress Find Categories By Name

The below works for both categories, and other custom taxonomies (e.g genres) you may have.

Find category by an exact match

$cat = get_term_by( 'name', $cat_name, 'category' );

Find category by partial match anywhere

$categories = get_terms( 'category', array( 'name__like' => 'cat_name' ) );

Find category by partial match from the start of the string

$categories = get_terms( 'category', array( 'search' => 'cat_name' ) );
Enjoyed the content ? Share it with your friends !

Leave a Reply

Your email address will not be published. Required fields are marked *