In Gutenberg, one can use the getEntityRecord selector to get the data of a term of a specific taxonomy by its term id:

// Get the category term with term id = 25
const term = useSelect( ( select ) =>
    select('core').getEntityRecord( 'taxonomy', 'category', 25 )
);

My question is, is there a way to get the data of a specific term by using the term slug instead of the term id? If so, how?

1 Answer
1

I think one could search for a given term slug with getEntityRecords:

select('core').getEntityRecords( 'taxonomy', 'category', { slug : 'my-slug' } )

by skimming through the endpoint reference that supports the slug query parameter.

Leave a Reply

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