Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Just exceptional. Thank you so much, Jack, you smashed it.

— Hugo, Developer

Taxonomy Repository

To work with the with Taxonomy Repository, use the following Facade:

use Statamic\Facades\Taxonomy;

Methods

Methods Description
all() Get all Taxonomies
find($id) Get Taxonomy by id
findByHandle($handle) Get Taxonomy by handle
findByUri($mount) Get Taxonomy by uri
handleExists($handle) Check to see if Taxonomy exists
handles() Get all Taxonomy handles
queryTerms() Query Builder for Terms
make() Makes a new Taxonomy instance
Hot Tip!

The id is the same as handle while using the default Stache driver.

Querying

While the Taxonomy Repository does not have a Query Builder, you can still query for Terms inside Taxonomies with the queryTerms method. This approach can be useful for retrieving Terms with an existing Taxonomy object.

$tags = Taxonomy::find('tags');
 
$tags->queryTerms()->get();

Creating

Start by making an instance of a taxonomy with the make method. You can pass the handle into it.

$taxonomy = Taxonomy::make('tags');

You may call additional methods on the taxonomy to customize it further.

$taxonomy
->title('Tags')
->cascade($data) // an array
->revisionsEnabled(false)
->searchIndex('tags')
->defaultPublishState('published') // or 'draft'
->sites(['one', 'two']) // array of handles

Finally, save it.

$taxonomy->save();
HR: Section
Learn More!

There is more to learn more in these related articles:

Tags

HR: Section
Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →