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 Loop does not include private posts #38688

Open
Tracked by #41405
mrfoxtalbot opened this issue Feb 10, 2022 · 1 comment
Open
Tracked by #41405

Query Loop does not include private posts #38688

mrfoxtalbot opened this issue Feb 10, 2022 · 1 comment
Labels
[Block] Query Loop Affects the Query Loop Block [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.

Comments

@mrfoxtalbot
Copy link

mrfoxtalbot commented Feb 10, 2022

Description

The Query Block does not display private posts. The public view does show all posts, including private ones, but the editor view only displays published posts:

Editor View:
Screen Shot on 2022-02-10 at 01:10:54

Public view:
Screen Shot on 2022-02-10 at 01:09:57

Step-by-step reproduction instructions

  1. Create two posts: One public, one private
  2. Edit the Homepage template in the Site Editor.
  3. Add a query loop
  4. Notice how the private post does not show
  5. Save and visit the public view: The private post is listed there,

Screenshots, screen recording, code snippet

Additional Screenshots using the TT1 Blocks theme.

Editor view:

Screen Shot on 2022-02-10 at 01:17:10

Public view:

Screen Shot on 2022-02-10 at 01:17:29

Environment info

  • WordPress 5.9
  • Gutenberg 12.5.4

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@mrfoxtalbot mrfoxtalbot added [Feature] Full Site Editing [Block] Query Loop Affects the Query Loop Block [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") labels Feb 10, 2022
@ntsekouras
Copy link
Contributor

ntsekouras commented Feb 18, 2022

Thanks for reporting this @mrfoxtalbot!

I looked into this and I couldn't find a proper solution for now. Here is what I could make out after investigating a bit

  1. There is a difference how the query results are handled in WP_Query and REST API. Specifically:

Default value is ‘publish‘, but if the user is logged in, ‘private‘ is added.

By adding explicitly in the REST request in Query status: ['publish', 'private'], fixes the problem for admins and editors, but messes with the results for others who are not allowed to view private posts. That is because the initial results are fetched and they are filtered afterwards here. This can lead for example if we have two private posts(expected first in the list) and we have posts per page two as well, in the editor the REST request will be an empty array.

I couldn't find in core if and where I could adjust this behavior. I also think from my searching that it should pass from the same flow and therefore the checks that happen in front end should also apply to the REST request.

A workaround that doesn't seem right is by filtering rest_post_query but feels hacky to me..

@TimothyBJacobs , @spacedmonkey do you have any input here as you've worked with the REST API a lot?

@jordesign jordesign added the [Type] Enhancement A suggestion for improvement. label Sep 14, 2023
@jordesign jordesign changed the title Query Loop does not display private posts Query Loop does not include private posts Sep 14, 2023
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 [Feature] Site Editor Related to the overarching Site Editor (formerly "full site editing") [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants