WAIT: Template Element Uses Wrong Query Data if it is used in a Template that has another element that is a Query

Bricks Version: 1.6.1

I have a section template for a hero that contains dynamic data that shows the featured image and post title.

I insert this section template (using the template element) at the top of my other templates that I want to have the same hero.

This includes my regular page template, CPT service page template, services archive template, and search template.

The temple element works fine on my regular pages and my CPT pages but if it is a page that has a query like an archive template or search template it does not show the featured image and post title of the actual template but uses the featured image and post title from the query within the template.

The template element should use the main query of the page not a query that runs within the page (unless of course the template element is a child element of another element which is an actual query)

5 Likes

By the way it displays the data correctly in the editor. It is just incorrect on the front end for the archive and search templates.

I think this is likely related to the bug at WIP: Query loop for posts not working on all product archive pages.

I’ve checked my search results page (Bricks Template) and this also fails to output a different post loop under the search results for me. This would explain the issue I see on WooCommerce archive templates, because the products shown in the post loop mean the second loop of a different post type below it fail to render.

And as reported by OP, this renders in the Bricks editor UI but not on the front end page. Is there any progress on this issue @timmse ?

Seems like it. It also seems it may be related to this one as well that I found:

I did try the “fix” where you add a code snippet to disable the merging of the 2 queries but that did not work either. Even though in my opinion I don’t see why the queries would be merged…

Surprised more people are not complaining about this issue since using the template element this way reduces the amount of maintainable code.

Any word on the progress on this issue (or related ones) @timmse ?

Hi @Tom ,

If you are using Query Loop in archive template, the query parameters will be auto-merge with WP main queries by Bricks.

You could exclude the merge for that particular query loop by using this filter:

Please let me know if this works.

By the way, the dev team will add a checkbox in the Query loop UI so you could exclude the merge without the PHP filter.

Regards,
Jenn

2 Likes

Thanks for the reply. I actually did try adding the filter code to a code snippet (I linked to the post I found about it above) and it didn’t work . I am pretty sure I got the right query element ID when I did it. I wasn’t sure if it was the right solution though so I didn’t investigate it more as to the reason why it wasn’t working.

I’ll try it out again. Thanks (and a good idea to add a checkbox in the query loop ui)

Alright, appreciate your update after the try :slight_smile:
Thank you.