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: validate in_the_loop() to true #32896

Open
RavanH opened this issue Jun 22, 2021 · 1 comment
Open

Query block: validate in_the_loop() to true #32896

RavanH opened this issue Jun 22, 2021 · 1 comment
Labels
[Block] Query Loop Affects the Query Loop Block Needs Technical Feedback Needs testing from a developer perspective. [Type] Enhancement A suggestion for improvement.

Comments

@RavanH
Copy link

RavanH commented Jun 22, 2021

What problem does this address?

Wanting to filter post links on a classic archive template, I could hook into the post_link filter and then do a in_the_loop() check to make sure to only work on links in the post archive, not in the menu for example.

But The Loop on a block based theme (like block-base) is done with the wp:query block. This loop however, does not set $wp_query->in_the_loop to true. This makes the above example fail on the Query block loop while working on a "regular" loop.

What is your proposed solution?

Make Query block loops behave more like regular loops, starting with $wp_query->in_the_loop :)

@JakePT
Copy link

JakePT commented Jul 26, 2022

This is something I'm also interested in. In ElasticPress we have a server-rendered block that should only display if there is a current post. So only on singular pages or inside a loop. The problem is that we surprisingly can't use in_the_loop() in the block's render function because it returns false inside the query loop block.

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 Needs Technical Feedback Needs testing from a developer perspective. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants