I have three categories: Money, Space, Advice
.
I use these on a post index page to filter through all of my posts by creating checkboxes for each category type.
@php $categories = get_categories() @endphp
@foreach($categories as $category)
<div class="custom-control custom-control-inline custom-checkbox">
<input type="checkbox" name="{{ $category->slug }}" value=".{{ $category->slug }}" class="custom-control-input" id="{{ $category->slug }}">
<label class="custom-control-label" for="{{ $category->slug }}">{{ $category->name }}</label>
</div>
@endforeach
This creates a checkbox list of every category in use.
Is there a way to limit get_the_categories()
to specific post types?
For instance, if I have a post type called team-member
I still want to use Money, Space, Advice
for categorisation but I don't want filters to appear if the categories are unused for that post type.
However, using get_the_categories()
would display used categories in any post type, this means that for a custom post type there may not be anything categorised but the filter would display, which is misleading.
So, I'm wondering if there's something like get_the_categories('team_member)
?
get_categories()
? That's the correct function, and what you have in your code, but you mentionget_the_categories()
throughout your question.