Jump to content

Recommended Posts

Posted

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?

Posted

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
Posted

It's just not outputting anything for me.

echo $page->editions[0]->id;

This outputs nothing.  However if I publish one PageTable page, it correctly echos the ID.

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

Posted

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?

Posted
12 minutes ago, adrian said:

Seems like a bug to me - anyone else?

Keep in mind that the find() in your example is only in-memory filtering. It cannot find additional pages.

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

Posted
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;

 

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
×
×
  • Create New...