Jump to content

Fields not returned in $page


MarkE
 Share

Recommended Posts

Having used PW for a few years now, I feel that this is a really basic question about something that ought to be obvious to me! So I'm prepared to say 'doh!'

If I get a page object via the $page API (or page() or $pages or whatever) it doesn't always seem to have the fields fully populated.

For example, here is the 'Field List & Values' display (partial) for a page 'gallery-of-apples', it has 5 fields:

1267103997_gallerypageexamplefields.thumb.jpg.be25407eb35ff4c740907ba0412f4d3b.jpg

If I call $page and dump it, all I get is the title field, but by getting the fields via getFields() and setting them, I get the complete picture - see Tracy console image below:

118297960_galleryconsole.thumb.jpg.76c8662bfd94fd28caab7be79d62b511.jpg

What is going on here? Why don't I get all the fields and values with $page?

Link to comment
Share on other sites

  • MarkE changed the title to Fields not returned in $page

Thanks @Robin S . Sort of ‘doh’ as I had heard of autojoin, but never used it or looked into it. That post explains everything, although I wonder if some fuller documentation in the API for $page might be helpful. I guess using autojoin is more efficient than getting the page then using getFields(). 

Link to comment
Share on other sites

@MarkE, besides the autojoin setting in admin that's mentioned in Ryan's post, you can also set autojoin programmatically when you get one or multiple pages.

For multiple pages ("find") see the blog post: https://processwire.com/blog/posts/find-faster-and-more-efficiently/

And if you only want a single page ("get") then you can use "joinFields" in the $options argument, e.g.

image.png.a37a391356340e5d44803aa60c93ccae.png

Edit: it seems you can use the "field=" syntax described in the blog post with $pages->get() and $pages->findOne() too...

image.png.a636ab680b0ddfefd35cb6c445b3239e.png

  • Like 3
Link to comment
Share on other sites

Thanks for all the tips, @Robin S. However one of the fields I need is a repeater matrix and that doesn't seem to support autojoin. Also, while I could get autojoin to work (for other fields) via the field settings, I couldn't replicate your example in my system - none of the requested ('autojoinable') fields were joined. I am on PW 3.0.206.

findRaw() works as documented and gets all the fields and may be usable for my purposes, but that doesn't feel like the right answer.

It seems like findJoin might be a bit buggy - I'm not sure @adrian's issue 

 has been resolved.

But it may be something strange in my set up.

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