Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query Block: not rendering on front-end of site in page content #28334

Closed
ianstewart opened this issue Jan 19, 2021 · 8 comments · Fixed by #28351
Closed

Query Block: not rendering on front-end of site in page content #28334

ianstewart opened this issue Jan 19, 2021 · 8 comments · Fixed by #28351
Assignees
Labels
[Block] Query Loop Affects the Query Loop Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended

Comments

@ianstewart
Copy link
Contributor

The query block appears to fail to render on the front-end of a site in page content as seen in the screenshot below, with the query block in page content on the left, and the published front-end result on the right.

image

  • WordPress 5.6
  • Gutenberg 9.7.4
  • Theme: TT1 Blocks (also tested with "Q" theme)
@ianstewart ianstewart changed the title Query Block: not rendering on front-end of site in page content. Query Block: not rendering on front-end of site in page content Jan 19, 2021
@ntsekouras
Copy link
Contributor

Hey @ianstewart - The problem here lies to the inherit query from URL option that defaults to true and therefore in a page/post context doesn't work as expected because the $wp_query is about the single page.

Can you try setting the above mentioned option to false, so as to close this issue?

I know this is confusing and easy to miss and I've made some explorations on detecting the FSE and page/post context, but needs more thinking and work on context detection..

@ntsekouras ntsekouras added the [Block] Query Loop Affects the Query Loop Block label Jan 20, 2021
@gziolo
Copy link
Member

gziolo commented Jan 20, 2021

There is also this question of whether the query detected from the URL should only trigger filtering when it's one of the pages that display a list of posts. In the case of the single page type, it could use all possible posts by default — just an idea to explore. Finding sensible defaults is very important here.

I would like to hear thoughts from more people building FSE themes: @scruffian, @aristath, @carolinan.

@MaggieCabrera
Copy link
Contributor

There is also this question of whether the query detected from the URL should only trigger filtering when it's one of the pages that display a list of posts. In the case of the single page type, it could use all possible posts by default — just an idea to explore. Finding sensible defaults is very important here.

I agree with that perception, it would be what I expected as a theme developer

@scruffian
Copy link
Contributor

This caught me out too. I think that when "inherit query from URL" is turned on, the other options should be disabled. I also wonder if it should move to the block toolbar, so that its more obvious...

@aristath
Copy link
Member

The problem here is the empty post_type argument in the query. Since it's empty, get_posts() defaults to post and so it doesn't work for pages.
For the sake of an example, I created an FSE theme with nothing but an index.html template in it. In that template I added a query block and nothing else. On the frontend: It worked for archives showing multiple posts. It worked for single posts by showing that single post. But on pages it was empty because it was a different post-type.

Currently debugging this to see if there's an easy way to define the post-type 👍

@aristath
Copy link
Member

PR in #28351

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Jan 20, 2021
@aristath
Copy link
Member

There is also this question of whether the query detected from the URL should only trigger filtering when it's one of the pages that display a list of posts. In the case of the single page type, it could use all possible posts by default — just an idea to explore. Finding sensible defaults is very important here.

I'd expect the exact opposite... If I add a query block and set it to inherit the global query, then I expect it to inherit the global query. When viewing a single post, the global query contains that single post/page, so that's what I'd expect it to show by default.
Just like in a classic theme I could add an index.php file with a loop and have it work properly everywhere, showing the content for whatever page I'm on - regardless of whether it's an archive or a page, post etc.

@gziolo
Copy link
Member

gziolo commented Jan 20, 2021

Just like in a classic theme I could add an index.php file with a loop and have it work properly everywhere, showing the content for whatever page I'm on - regardless of whether it's an archive or a page, post etc.

Thank you for sharing this use case. I'm perfectly fine with preserving the same behavior as long as it's predictable and works correctly. That makes this issue a bug then.

@gziolo gziolo added [Type] Bug An existing feature does not function as intended and removed [Type] Enhancement A suggestion for improvement. labels Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Query Loop Affects the Query Loop Block [Status] In Progress Tracking issues with work in progress [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants