Jump to content

hidden pages are showing in custom list


asbjorn
 Share

Recommended Posts

I have a page that are either ) showing an automatic list of all pages with a certain template, if no pages are selected in a page field. 2) Or showing the selected pages from the page field.

if ($page->custom_menu->count == '0') {
	$subjects = $pages->find("template=subject-page, sort=title");
}
else {
	$subjects = $page->custom_menu;
}

When I set these "subject-page"-pages to hidden. The first option excludes these from the list as they should. But the second manually selected list will still show hidden pages. I have checked that these are actually hidden, with the following code:

if ($subject->status & Page::statusHidden) {
	echo "I'm hidden!";
} else {
	echo "And I'm visible!";
}

If I am not wrong, hidden pages have been removed from page fields by themself before, because of their status. But I'm not sure. I haven't used include=hidden. I am on ProcessWire 3.0.32, the page field is using PageListSelectMultiple*+.

Link to comment
Share on other sites

Hidden means "excluded from lists and searches" so doesn't affect if the page can be selected in a Page field. Well, not unless you explicitly exclude hidden pages with a custom selector in the field settings as @horst suggests.

Try:

$subjects = $page->custom_menu->find("status!=hidden");

 

  • Like 1
Link to comment
Share on other sites

40 minutes ago, horst said:

How do you or the customer can add pages to


$page->custom_menu

?
What are the settings for that. Are there hidden pages included, selectable?

I am able to select hidden pages, and save, and they are still there in the page field in the page edit mode. The field settings for custom_menu are "nothing special". A standard page field, with a custom name, title as label, PageListSelectMultiple*+ as input fieldtype. No custom values in other input fields.

13 minutes ago, Robin S said:

Hidden means "excluded from lists and searches" so doesn't affect if the page can be selected in a Page field.

Try:


$subjects = $page->custom_menu->find("status!=hidden");

 

I understand, so I should really unselect it from the page field if I want to do i correctly? I also tried your option, but the pages are still shown.

Link to comment
Share on other sites

Wow, this is proving much more difficult than I thought. Seems that you cannot use a string like "status!=hidden" in a selector (although some posts suggest otherwise).

Debugging shows that status is an integer and the different statuses are cumulative so you can't just check if the status equals a constant like Page::statusHidden but must use 'greater than' or 'less than'.

This is the best I've been able to manage:

$subjects = $page->custom_menu->find("status<" . Page::statusHidden);

Surely it should be easier than that to use status in a selector?

Link to comment
Share on other sites

5 minutes ago, Robin S said:

Seems that you cannot use a string like "status!=hidden" in a selector (although some posts suggest otherwise).

That's because of the differences between the database querying $pages->find() and the runtime only $somePageArray->find(). The first one does parse status keys and date strings and alike, whereas the latter does not do such conveniencies.

  • Like 1
Link to comment
Share on other sites

3 minutes ago, LostKobrakai said:

That's because of the differences between the database querying $pages->find() and the runtime only $somePageArray->find(). The first one does parse status keys and date strings and alike, whereas the latter does not do such conveniencies.

Ah, good to know, thanks.

Therefore in a case like this where you want to filter pages in a Page field I'd be inclined to do an extra $pages->find() for the sake of better readability.

$subjects = $page->custom_menu;
$subjects = $pages->find("id=$subjects, status!=hidden");

 

  • Like 2
Link to comment
Share on other sites

Just keep in mind that this will be another mysql query, whereas the other call is made in php runtime. It won't load the page's another time (as they are already loaded), but the selector does still need to query the db to know which pages to return.

  • 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...