Jump to content

Need Help in FieldTypePage


dhruba
 Share

Recommended Posts

Hi

I got some strange problem need help. I have two template order and customer , order has customer FieldTypePage. When I want to retrieve the customer information ...............

$orders = $pages->get('/orders/');
foreach($orders as $order){
$c = $order->customer;
$cp = $pages->get($c);
echo $c.'/'.$cp->title.'</br>';
}

output................

1042/Home

1043/Home

but when I put $pages->get(1042); I got correct ans. Thanks............

Link to comment
Share on other sites

I am not sure on your page structure, but looking at your code in more detail, do you need to do something like:

$orders = $pages->get('/orders/')->children();

or if this code is in the orders page template, then you could just do:

$orders = $page->children();

At the moment your ->get will only return one page - the orders parent.

Also, did you try the ->first()->title option?

  • Like 1
Link to comment
Share on other sites

->first() This works but I don't Understand why.

$orders = $page->children();

foreach($orders as $order){
$c = $order->customer;  //$c = $order->customer->first();  works $order->customer why return pagearray I have only one page linkd
$cp = $pages->get($c);
echo $cp->title.'</br>';
}

Link to comment
Share on other sites

Because in the details tab of the customer field you must have it set to "Multiple Pages". Change it to a single option and you won't need first() anymore. You should only have it set to multiple if you want multiple customers assigned to each order.

  • 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

  • Recently Browsing   0 members

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