xxxlogiatxxx Posted September 17, 2019 Share Posted September 17, 2019 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? Link to comment Share on other sites More sharing options...
rick Posted September 17, 2019 Share Posted September 17, 2019 Something like this maybe? // Just thinkin' out loud foreach ( $page->getInputFields() AS $fld ) { fldArray[] = $fld; } flsJson = json_encode( $fldArray ); Link to comment Share on other sites More sharing options...
BitPoet Posted September 18, 2019 Share Posted September 18, 2019 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now