Jump to content

$page->isPublished() method #request


SwimToWin
 Share

Recommended Posts

As an admin I want to use the API to ask if a page is published - using the $page->isPublished() method - so that I know it's published - as opposed to unpublished or trashed pages. That includes hidden pages.

This method will correspond to Settings -> Status when editing pages:

page-status.png.687c6020a4c73de76bcb28c76c3a74b6.png

(Published is also mentioned explicitly where the edit page says "Published on [?]".)

I would expect the API - and specifically the $page->hasStatus() method - to ask if a page has status published.
But as I can see, it's only possible to ask for exceptions such as isUnpublished() and isHidden().

<?php
// This fails with "Fatal Error: Uncaught Error: Undefined class constant 'statusPublished'"
if($page->hasStatus(Page::statusPublished)) { echo 1; }
?>

PS: My current use case is that I want to count number of published vs. unpublished pages. I can only do that by getting all pages (include=all), then subtract any unpublished pages.

Link to comment
Share on other sites

  • 2 weeks later...

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