Jump to content

Strange find() / children() selector behaviour


Wesley
 Share

Recommended Posts

Hi,

We encountered a strange problem regarding the selector behaviour in find()/children().

Background information:

Our page setup regarding the templates/fields that go wrong is as follows:

- Root pages

- Root pages

- - Some subpage

- - Some subpage

- - - FAQ (faq-overview)

- - - - Question category 1 (faq-category)

- - - - - Question / answer 1 (faq-detail)

- - - - - Question / answer 2 (faq-detail)

- - - - - Question / answer 3 (faq-detail)

- - - - Question category 2 (faq-category)

- - - - - Question / answer 1 (faq-detail)

- - - - - Question / answer 2 (faq-detail)

- - - - - Question / answer 3 (faq-detail)

- - - - Question category 3 (faq-category)

- - - - - Question / answer 1 (faq-detail)

- - - - - Question / answer 2 (faq-detail)

- - - - - Question / answer 3 (faq-detail)

- - - - Question category 4 (faq-category)

- - - - - Question / answer 1 (faq-detail)

- - - - - Question / answer 2 (faq-detail)

- - - - - Question / answer 3 (faq-detail)

Please note that both faq-category and faq-detail are hidden pages, due to the fact that we only wish to display them on faq-overview, not any where else.

What's happening:

We are using the following selectors to load the faq-categories and within the faq-detail pages.

$page->children->find("template=faq-category, include=hidden")

Then, for each child of that result, we use the following code:

$questionCat->children->find("template=faq-detail, include=hidden")

Results from both selector queries are 0 results. If we only use template=faq-category, 14 results (of the 18 pages, a few are unpublished, a few are hidden).

If we use the code above, or any variation on it, zero results. None of these work:

$page->children->find("template=faq-category, include=hidden")
$page->children->find("template=faq-category, include=all")
$page->children->find("template=faq-category, status=hidden|published")

And now for the strangest part (because I could've just done it wrong, couldn't I):

The following code dóes work and returns 16 results (the 14 published ones, 2 hidden ones, and the 2 unpublished ones aren't included, as should be):

$pages->find("template=faq-category, status=hidden|published, parent=" . $page->id)
$pages->find("template=faq-detail, status=hidden|published, parent=" . $questionCat->id)

If anyone is able to give us any insight as of why this is happening and whether it's because we made a mistake (or it's a bug in ProcessWire? Can't imagine but... you never know), that would be great!

Link to comment
Share on other sites

Just quickly. You should use

$questionCat->find("template=faq-detail, include=hidden")

Or same as only searching children

$questionCat->children("template=faq-detail, include=hidden")

since a children is already like a find it will ignore hidden and then you do a find on the results... doesn't work as you may expected.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...