Use get_terms()
, which uses WP_Term_Query
under the hood. For a full list of all the available parameters check out the documentation for WP_Term_Query::__construct
// Get term *IDs* with name that *matches* "my_name"
$term_ids = get_terms([
'fields' => 'ids',
'taxonomy' => 'category',
'name' => 'my_name',
'hide_empty' => false,
]);
// Get term *objects* with name that *matches* "my_name"
$terms = get_terms([
'taxonomy' => 'category',
'name' => 'my_name',
'hide_empty' => false,
]);
// Get term *objects* with name that *contains* "my_name"
$terms = get_terms([
'taxonomy' => 'category',
'name__like' => 'my_name',
'hide_empty' => false,
]);