Post Loop filtered by Parent Term

I am trying to create a Post Loop that is filtered by a Parent Term - but cannot figure out how to make this work.

Basically my structure is:
Custom Post Type = Product
Taxonomy = product-type
Term (Parent) = ales

Each product is assigned to a child term under a parent term that I am specifying to the query (in this case “ales”). I need to loop through all posts that are assigned to these child terms and sort by a custom field. In PHP, I could do this with a $tax_query array, set the parent term id and set include_children= true. Is this possible in L&L?

Hi Brandon, thank you for the question.

OK, if I try to translate your description directly, it would look like:

<Loop type=product taxonomy=product-type terms=ales>

However, this will only get products which are assigned to the parent term.

The Loop tag does have a parameter called include_children, but it applies to post children, not taxonomy terms. Looking up WP_Query’s taxonomy parameters, I see that indeed there is a parameter of the same name that includes child terms for hierarchical taxonomies. Checking in the plugin code, currently the Loop tag sets that to false by default, and there’s no way to set it to true.

OK, I’ll add a new parameter child_terms=true for this purpose. It will be included in the next plugin version, I’ll write another comment here when it’s released.

And sorting by custom field, it can be achieved with orderby_field if the field value is plain text; or orderby_field_number if the value is number.

All together, it would be:

<Loop type=product taxonomy=product-type terms=ales child_terms=true orderby_field=some_field>

Hi Brandon,

In the newest plugin version, the Post loop type supports child_terms=true to include child terms for hierarchical taxonomies. So this snippet should work now:

<Loop type=product taxonomy=product-type terms=ales child_terms=true orderby_field=some_field>