Jump to content

Get unformatted field values in page array


MarkE
 Share

Recommended Posts

I have a selector:

$pageArray = $pages->find("template=basic-page, length.magnitude>0, include=all");

I would like an array of each of the 'length' fields. However, the field is an object and $pageArray->each('length') returns the formatted values; I want the unformatted objects.

I thought perhaps I could use a callable like:

$pageArray = $pages->find("template=basic-page, length.magnitude>0, include=all");
$lengths = $pageArray->each(function($p) {
    $length = $p->getUnformatted('length');
    return $length;
});

but it seems that only strings can be returned and those are concatenated.

So it looks like I have to use a foreach() loop - which works, but I was expecting some neater shorthand. Any thoughts?

Link to comment
Share on other sites

Found it!

$pageArray = $pages->find("template=basic-page, length.magnitude>0, include=all");
$lengths = $pageArray->each(function($p) {$p->of(false);})->each('length');

I hadn't originally thought about chaining eaches, but of course that is possible if the result is a wire array.

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