"Query Type" missing from Query Loop block; can no longer use it to inherit current query?
Description
I went to create a Template Part for Search Results and I noticed I was not able to allow the Query Loop block to inherit the current query. I then went to multiple sites running 6.7.1 and found the same result.
I disabled all plugins and used TwentyTwentyThree to rule out any plugins or theme conflicts. This setting is 100% missing.
Step-by-step reproduction instructions
- Add a Query Loop
- Notice the setting is missing
Screenshots, screen recording, code snippet
Environment info
No response
Please confirm that you have searched existing issues in the repo.
- [x] Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- [x] Yes
Please confirm which theme type you used for testing.
- [ ] Block
- [ ] Classic
- [x] Hybrid (e.g. classic with theme.json)
- [ ] Not sure
Follow up: I now see that the "default behavior" is to have the query loop inherit by default:
https://make.wordpress.org/core/2024/09/23/core-editor-improvement-simplified-query-loop-block-with-smarter-defaults-intuitive-settings/
The documentation has not been updated, which is very confusing:
https://wordpress.org/documentation/article/query-loop-block/#inherit-query-from-template
Anyway, this would be fine, except it doesn't actually work; I'm adding it to a Template Part and it's wanting to just query a post type and it's not reacting to user searches.
This one is also about Query Loop & Template parts: https://github.com/WordPress/gutenberg/issues/38684
I am not able to reproduce this issue:
Activate Twenty Twenty-Three. Go to Appearance > Editor > Patterns Click on the button "Add new pattern": Select "Add New Template part". Select the "general" area and add a name. Select "Add".
In the editor, add a query loop. The option "Query Type" is available and Default is enabled. Save.
Go back to Appearance > Editor > Templates and select the Search Results template. Insert a template part block. Select "Choose" and then select the part you just created. Select the query block inside the part. The option "Query Type" is available and Default is enabled. Save.
Go to the front of the website and perform a search. Confirm that the newly added query displays the search results.
It is not possible to use the query loop's standard interface controls to query search results for a custom post type. The block can not both inherit the query and use a custom query for post types.
Can you please help narrow down what the issue is? Because I don't believe that the problem is that the control in the sidebar is not showing. It would be helpful if you could describe in detail what you are trying to accomplish.
I believe what you want to look at is this: https://github.com/WordPress/gutenberg/pull/40585
Hello @cheestudio, I can't able to reproduce the issue. For me, the setting is showing.
=== Environment
- WordPress: 6.7
- PHP: 8.1.23
- Server: nginx/1.16.0
- Database: mysqli (Server: 8.0.16 / Client: mysqlnd 8.1.23)
- Browser: Chrome 131.0.0.0
- OS: macOS
- Theme: Twenty Twenty-Five 1.0
- MU Plugins: None activated
- Plugins:
- Gutenberg 19.9.0
- Test Reports 1.2.0
@carolinan and @rinkalpagdar
I am running a Hybrid and it looks like this deals with having parts already defined in the theme, but then are editing within the dashboard, that seem to upset the inheritance of the search part. My template part was defined prior with the following:
But after the part was edited, I copied it back to the HTML file and noticed this:
So something about editing the part changed that default value to false. Since the toggle is removed now due to it inheriting by default, I was forced to change it manually, remove the part from the theme and dashboard entirely, and then re-add it with the updated version that I was wanting to use.
Perhaps it's my hybrid theme, although I have no functions where I can see that would incur this behavior and I don't have problems with parts in general otherwise. It feels like a bug.
Ultimately I abandoned this process entirely, as the Query Loop doesn't support multiple post types anyway, and my search result needed to be scoped to multiple post types and variations. It seems I just hit a limit of what FSE capabilities can do in this case.
Please understand that when you use screenshots of code, it makes it impossible for contributors who are blind to access the code; And impossible for sighted contributors to copy the code for testing.
So something about editing the part changed that default value to false.
Without knowing what was edited, it makes it impossible to reproduce with exact steps.
I think this is a duplicate of #66790. The "Query type" settings are only displayed when a Query loop block is used in archive/index templates.
See this comment for additional details - https://github.com/WordPress/gutenberg/issues/66790#issuecomment-2461953873.
I don't think the issue is that the setting is not showing, but that they are asking for help with a custom query. I think it can be closed.
Let's see if we can get any additional info. Otherwise, we can close it 👍
I believe I am seeing the same issue as @cheestudio and I agree with him that it seems like a bug. To outline:
- I am developing a classic theme.
- I have a added a query loop block to my posts page using the block editor.
- My posts page shows the appropriate posts. However, my search and archive pages (which are using the same template as the posts page, i.e. index.php) do not display any posts. The query loop block is rendering, but it contains no posts.
- When switching the the code editor, I see that the inherit attribute is set to false.
- I use the code editor to set the inherit attribute to true and save the page. My search and archive pages now list the appropriate posts.
- However, as soon as I exit the code editor, the inherit attribute reverts to false, and my search and archive pages no longer work.
This is an issue as I am building a theme for a client and I can't ask them to change the attribute in the code editor anytime they want to edit the page.
@genemma thank you for taking the time to detail your experiences and steps; that's basically what I am noticing, as well.
Thanks for the additional details, @genemma! That's very helpful.
@Mamaduka I am happy to provide any more information that may be helpful. Thank you.
@Mamaduka I can confirm we're running into similar issues at Greyd with our classic theme and the use of queries in the block editor to what @genemma has described. This is actually causing issues on client sites at the moment. Let me know if you need further information for debugging and what would be useful.
Thanks, everyone, for the confirmation. I think I know where regressions were introduced.
Do you mind giving me step-by-step reproduction instructions for any default classic theme?
I have now tried to dive into the code a bit deeper to understand the problem behind this and I'm not sure if this may be more of an Extensibility issue.
The original change was introduced in this PR: #65067, with two follow-up PRs #65483 and #65820. It basically turns off the Default/Custom toggle that is present in the Query Loop block AND forcing inherit to be always false, even if you manually try to set it to true via the code editor and then switch back to the visual editor.
In the Greyd plugin and with the classic (not a block theme!) Greyd.Suite theme, we've created a templating system similar to what is today's wp_template system is. We have a custom post type called dynamic_templates that has some rewrites, so any custom and Core templates like archives, search, pages etc. can be created there and edited with the block editor. Now with the above mentioned changes introduced, queries in templates for search, archives and any that depend on inherit being true do no longer work, as to edit the templates, the block editor is used.
While I can understand the reasoning behind the change, the hard force is breaking backwards compatibility at least for our product.
If I'm not mistaken, the hard force appears to happen in this file: https://github.com/WordPress/gutenberg/blob/3ed56acb9472eebc82d2ebad2d9b9e291f577298/packages/block-library/src/query/utils.js#L447-L450 which is called in this file: https://github.com/WordPress/gutenberg/blob/444854db0f21d2bf292c1bf2bdd8a2c63a20e255/packages/block-library/src/query/edit/query-content.js#L104
I'd like to discuss how we can get this working again with a filter or something else code-wise. Ping @Mamaduka
I wonder if we should take a different approach to resolve #64746 and revert the force setting of the query.inherit value.
Why?
Calling setAttributes in life-cycle events should be avoided in 99% of cases unless the block really needs to enforce that attribute value. Introducing more conditions in the setting of the attributes creates more variables and makes these life-cycle events flaky. It doesn't allow changing behavior when the consumer knows what they're doing. Additionally, it can cause excessive re-renders and degrade performance.
A possible alternative
Show a warning with an action to switch inheritance off when the query block is inserted in post content. Consumers intending to use "inherited" queries in their posts are aware that the rendered content does not match what appears on the front end. Here, I assume that a warning should be more acceptable than fake query items.
cc @fabiankaegy @mikachan
Update: I added the mockup; the warning text is just an example.
Screenshot
@Mamaduka I'm a fan of your idea, my colleagues approve it too! When the user clicks on "Switch to Custom", the regular Query Loop block and settings would appear, is that the inteded user experience?