Get term by slug in Gutenberg

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x