SOLVED: Query Loop: Problem with tax_query and include_children

Bricks Version: 1.6.2

I think there is an issue with the query loop’s tax_query:

By default the “Include children” option in the Query Loop settings is disabled.

CleanShot 2023-01-19 at 16.44.40

With the option being disabled the include_children parameter is not included in the generated tax_query at all.

The problem is that the default value for the include_children parameter (if not explicitly set) is true (see WP_Query | Class | WordPress Developer Resources).

Because of this there is currently no possibility to exclude the children using the Query Loop (without using the query_vars hook to fix the tax_query) – the children are always included.

  1. If you leave the option disabled in Bricks the query parameter is omitted which results in WP’s default value being used. Which is true.
  2. If you enable the option in Bricks the query parameter is explicitly added with a value of true.

Hope my explanation was understandable. :sweat_smile:

1 Like

Hi @aslotta ,

Thank you so much for the detailed explanation.
Understand the problem.
Seems like the Include children should change to Exclude children (set false to include_children param) will be making more sense, agree?

Regards,
Jenn

In my opinion it would be the „most correct“ way (looking at the official WP_Query documentation) to have the switch in Bricks being enabled by default. In this case the include_children parameter would not have to be included in the generated query at all since it is the default WP_Query behavior to include the children.

Only if the Bricks user then disables the toggle explicitly the parameter should be included in the query with a value of false.

Reading your answer again… it is the same as mine. Just switching from include to exclude. So yes. Either way would work. Mine is just more of a 1:1 copy to the original behavior. :relaxed:

Thanks in advance, Jenn!

2 Likes

Hi Andre,
We’ve fixed this bug in Bricks 1.7 beta, now available as a manual download in your Bricks account: Account – Bricks

Please let us know if you are still experiencing issues.

Best regards,
timmse

2 Likes

Still an issue for me… in that it still includes children…

This gives me all posts in category 3, and all the subcategories of 3.

1 Like

True.

@timmse: Unfortunately the fix in 1.7 does not seem to work because the include_children value is passed to the query as a string (“true” / “false”) instead of a boolean (true / false). Sorry for not noticing this earlier.

Using the query_vars hook things work as expected:

Here you can see the fix in action.

Would be good to simply enable a category__in option, as this only returns parent posts.
Breakdance has a query builder - it’s not nearly as good… BUT… it also has a text and array option, enabling you to manually enter the parameters, with almost identical syntax to wp_query.
This would be a lovely option for Bricks.

Hi guys,
I was able to reproduce the issue and added it to our bug tracker - again :v:

Thanks for the suggestions Mike! I added them to the task, let’s see what the devs think about it :slight_smile:

2 Likes

Hi guys,
With Bricks 1.7.1 it should work as expected, now available as a one-click update in your WordPress Dashboard.

Please let us know if you are still experiencing issues.

Best regards,
timmse