Jump to content

page->status of '0'


Neeks
 Share

Recommended Posts

I'm trying to figure out the correct way to set page statuses.

if I do this:

$page->status = Page::statusUnpublished;
$page->save();

Then change your page status to published in the admin to published. The new pages status becomes = 0; it should be 1.

 if ($page->is(Page::statusOn)) {  //Page::statusOn =  1
    //do somthing
 }

The above code will fail to make it inside the if statement. I am trying to figure out how to test if a page is published or not and set page statuses that play nice with the Admin.

Since I don't understand these bitmasks, if any one can show example of how you add these page statuses together and remove page status without loosing them, that would be supper helpful. 

Link to comment
Share on other sites

You want to use addStatus so that your change goes from 1 to 2049 so that when you remove unpublished via the admin it takes off the 2048 that means unpublished and returns it to one. If you set the status directly to unpublished, it will end up being 2048 which is not what you want.



$page->of(false);
$page->addStatus(Page::statusUnpublished);
$page->save();

  • Like 3
Link to comment
Share on other sites

Thanks adrian. So I was trying to figure out how I was not able to find that information in the cheat sheet, or in my google searches and I realized that the: http://cheatsheet.processwire.com/  has a little button called "advanced" and it includes system functions like the one you where kind enough to mention above!  I guess I was not feeling that "advanced" when I was doing my searching ;-) Thanks again. 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...