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 block: Allow creating loop to display child pages #54461

Open
webmandesign opened this issue Sep 14, 2023 · 8 comments · May be fixed by #69053
Open

Query Loop block: Allow creating loop to display child pages #54461

webmandesign opened this issue Sep 14, 2023 · 8 comments · May be fixed by #69053
Assignees
Labels
[Block] Query Loop Affects the Query Loop Block [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Comments

@webmandesign
Copy link
Contributor

What problem does this address?

In one of my pages - it is a parent page that has nested/child pages - I'm trying to add a Query Loop block displaying the list of child pages. I can not seem to do so.

Here is how to reproduce:

  1. Create a page and name it "Parent page".
  2. Create multiple other pages and name it "Child page #" and set "Parent page" as a page parent.
  3. Go back to editing "Parent page" and try to insert a Query Loop block displaying the list of child pages assigned to this page.

Here is what I try to set for the Query Loop block used in "Parent page":

  • Post type: "Page"
  • Order by: "A → Z" (would be actually nice to select "Custom order"/"Order attribute")
  • Filters: there is no option to set "Current page as parent" so I've tried to set the "Parents" option to the ID of the page, which doesn't work

The loop does not display the child pages, it simply displays a list of all pages of the website.

What is your proposed solution?

  1. Would be great to have an option to display pages that have current page as parent (applicable for any hierarchical post type). And possibly also setting to display direct children only.
  2. Would be great to have an option to order query results by "Order" attribute.
@jordesign jordesign added [Type] Enhancement A suggestion for improvement. [Block] Query Loop Affects the Query Loop Block labels Sep 18, 2023
@annezazu annezazu changed the title **Query Loop** block: Allow creating loop to display child pages Query Loop block: Allow creating loop to display child pages Oct 9, 2023
@cagrimmett
Copy link

+1

@Drivingralle
Copy link

Drivingralle commented Jan 10, 2025

+1 for this need
Very helpful feature of many more complex websites also with CPTs.

My suggestion is to add some kind of option to the parents field of the query block.
No need for an extra setting.

@yogeshbhutkar
Copy link
Contributor

there is no option to set "Current page as parent" so I've tried to set the "Parents" option to the ID of the page, which doesn't work

I'm not sure if the following thing has been implemented over the years, but, I don't think we need to set an ID within the Parents option, it should rather be the name.

Screen.Recording.2025-01-23.at.12.12.45.PM.mov

I think we can already display the children of a Parent Page by the method mentioned above, I believe, what the issue boils down to is:

  • Within the Parents filter, add two toggles, the first specifies the usage of the current page as the parent page directly instead of manually entering the name of the current page, and the second specifies if the children should be direct descendent of the parent or not, by default, they are direct descendent.

I'd be happy to work on this enhancement.

@Drivingralle
Copy link

Drivingralle commented Jan 23, 2025

My goal with this feature is to be able to create templates for CPTs that contains a query to list child posts. As templates as HTML It's not possible to use PHP to dynamically set the current ID.
Have no opinion if it's a key word inside the parents attribute or a new attribute.

I guess it's a two step process. 1. Make it work from the template. 2. Add editor UI. Otherwise it breaks if a website owner wants to edit a template containing the feature.

@Drivingralle
Copy link

Just been digging around in a client project and noticed there is an "exclude":[], attribute for the query loop block. The attribute doesn't have any editor UI.

If we can add a keyword/"magic word" way to implement the adding of the current post to the parents array, the same could be reused to improve the exclude attribute.
That would allow the following use case: A query at the bottom of a blog post to list latest blog posts without the current post.

@webmandesign
Copy link
Contributor Author

@yogeshbhutkar

I'm not sure if the following thing has been implemented over the years, but, I don't think we need to set an ID within the Parents option, it should rather be the name.

You are right! I've tested it now and it works.

It is possible that I was confused in the past about what should I set the field to. I've tried adding page ID numbers.

So it seems the issue is UX related. Maybe some description text for the field could do the job? Something like "Start typing the title of the parent item" could help?

On my development server I have almost 3 seconds delay even when I start typing the parent page title before any results are shown, so that could cause my initial confusion that the field does not work.

But I can confirm now, displaying child pages query does work using this method.

Within the Parents filter, add two toggles, the first specifies the usage of the current page as the parent page directly instead of manually entering the name of the current page, and the second specifies if the children should be direct descendent of the parent or not, by default, they are direct descendent.

This would be a great enhancement to have! I'm all for that. And I think it could resolve @Drivingralle's issue too.

@Drivingralle
Copy link

My goal is to set the query inside a template to always query the children - no matter the name.

@PaulREnglish
Copy link

@Mamaduka Can I be assigned this ticket please? Thanks!

@github-actions github-actions bot added the [Status] In Progress Tracking issues with work in progress label Feb 5, 2025
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] Enhancement A suggestion for improvement.
Projects
Development

Successfully merging a pull request may close this issue.

6 participants