Query Custom Post Type / Custom (Sub)Category

I have a comprehension problem when creating a query for a custom post type (=mitarbeiter) with a custom category (=abteilung). The custom category has subcategories and is hierarchical.

I am trying to create a query of the posts of the post type with a specific subcategory. The subcategory should be specified in the shortcode.

I understand the query of the post type and the category but have a problem with the definition of the query of the subcategory. Can you help me here?

<Loop type=mitarbeiter taxonomy=abteilung parents=true ??="{Get local=subcategory of taxonomy abteilung}">

?? = is that “category” OR “abteilung” (the name of the custom category)

I think this is more of a WordPress mix-up than an L&L mixup. The important thing to realize here is that a “custom category” is not the same thing as a “custom taxonomy.” A category is one of the default taxonomies in WordPress. So if you’re actually working with a “custom category,” that implies that your taxonomy’s data structure looks like this:

> category-term
>> child-of-category-term

And since child-of-category-term is just a category term itself, if you wanted to only display posts in that category, your loop might look like this:

<Loop type=mitarbeiter category=child-of-category-term>

On the other hand, if you have a custom taxonomy that’s totally separate from WordPress’ category taxonomy, your data structure might look like this:

> taxonomy-term
>> child-of-taxonomy-term

Again, that child term is itself just a term, so your loop might look something like this:

<Loop type=mitarbeiter taxonomy=custom-taxonomy terms=child-of-taxonomy-term>

And then if you wanted to dynamically refer to the child term in your loop you’d just replace the value of the terms attribute with a local variable, as you sorta did in your example.

I hope that clears up the difference between a category and a custom taxonomy and based on which one applies to you you can choose the right approach above. I don’t think you’ll need to do anything fancy with parents=true or anything like that since it sounds like you simply want to display posts that have that child term applied, so the fact that it might be a child term of some other term doesn’t really matter at all since you’re ultimately just displaying posts that have a particular term applied.

1 Like

Thx for this explanation. For this case I use a “custom taxonomy”. This works perfect. The result ist now:

<Loop type=custom-post-type taxonomy=custom-taxonomy term="{Get local=term-of-custom-taxonomy}">

1 Like