Jump to content

Recommended Posts

Posted

Hello guys. Can anyone explain how to get all page fields and return them as json? 

$myPages = $pages->find('template=catalog-item');
$data = $myPages->explode(['title', 'created', 'some_field']);
echo wireEncodeJSON($data);

This code returned me id, created date but there is no fields. I need something like array(title: "Page title", body: "Some text", image_url: "/images/123.jpg"). 

Any ideas?

Posted

Something like this maybe?

// Just thinkin' out loud
foreach ( $page->getInputFields() AS $fld ) {
	fldArray[] = $fld;
}
flsJson = json_encode( $fldArray );



 

Posted

Perhaps PW's core PagesExportImport fits the bill there. The result is quite verbose and more nested though since it includes everything needed to recreate a page.

$myPages = $pages->find('template=catalog-item');
$PEI = new PagesExportImport();
export $PEI->exportJSON($mypages);

To get array data instead of a JSON string, call pagesToArray instead of exportJSON.

  • Thanks 1

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
  • Recently Browsing   0 members

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