Jump to content

How get all fields of every page?


hsanabria
 Share

Recommended Posts

I am creating a custom search routine. 

This code of Ryan has been very useful to encompass all fields of the page.

foreach($page->fields as $field) {echo "<p>";
echo "Field: {$field->name}<br />";
echo "Type: {$field->type}<br />";
echo "Value: " . $page->get($field->name);
echo "</p>";
}
But I failed to get the subfields of repeater's field type. 
 
It may be something simple, but I have several hours trying with unsuccessfully options.
 
Any suggestions?
Link to comment
Share on other sites

Adrian, I don't think that does what was asked. $fields will will get all the fields that you created, not the ones that are in the pages.

hsanabria, you have to identify which fields represent other pages. Using your example:

foreach($page->fields as $field) {
    $fieldValue = $page->get($field->name);
    echo $field;
    foreach($fieldValue as $innerPage) { // if value of the field is a page array, we can iterate it
        foreach($innerPage->fields as $innerPageField) {
              $innerPageFieldValue = $innerPage->get($innerPageField->name);
              echo $innerPageFieldValue;
        }
    }
}

Of course it would be much simpler to create a general function that iterates the fields of a page and call it recursively if that field is a page array. But I hope this serves as an example.

  • Like 3
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...