Jump to content

How to get PageTable pages when not published


alexcapes
 Share

Recommended Posts

I have a PageTable field (editions) that I need to access the top page even if the page is unpublished:

$page->editions[0]->id

This throws up an error when the top page is unpublished, however works fine when it's published.

I know I can't access the pages as children because the PageTable order differs from the child order, and I need the top page as it is in the PageTable field.

Any ideas how I may be able to do this?

Link to comment
Share on other sites

What exact error/exception are you getting? 

I just tried this in one of my installs and it works:

$price = $page->pricebulletin[0]; //unpublished pagetable page
wire('log')->save('dev','price: ' . $price->id);

maybe you're missing something else?

 

  • Like 1
Link to comment
Share on other sites

34 minutes ago, ottogal said:

Do you really need to unpublish the page? Why not just hide it?

It's a valid point - I think I may just have to rethink the workflow and require that editor publishes at least one PageTable page to be able to view the parent page.

Link to comment
Share on other sites

I don't really understand why:

$page->editions->find("include=all")->first()->title;

doesn't work.

I just tested:

$page->editions->find("sort=-sort")->first()->title;

which does work, so I think PageTables are missing the "include" option in the find selector.

Seems like a bug to me - anyone else?

Link to comment
Share on other sites

4 hours ago, ottogal said:

Do you really need to unpublish the page? Why not just hide it?

A PageTable field will not normally output a hidden page either. See here.

But you can use getUnformatted() to get unpublished or hidden pages.

$result = $page->getUnformatted('my_pagetable_field')[0];
//or
$result = $page->getUnformatted('my_pagetable_field')->first();

 

  • Like 4
Link to comment
Share on other sites

12 hours ago, Robin S said:

A PageTable field will not normally output a hidden page either. See here.

But you can use getUnformatted() to get unpublished or hidden pages.


$result = $page->getUnformatted('my_pagetable_field')[0];
//or
$result = $page->getUnformatted('my_pagetable_field')->first();

 

Just to note this works but does not seem to work outputting image fields.

Link to comment
Share on other sites

1 hour ago, alexcapes said:

Just to note this works but does not seem to work outputting image fields.

It works for me - what part isn't working for you?

$result = $page->getUnformatted('my_pagetable_field')->first();
echo $result->my_image_field->first()->url;

 

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