Jump to content

Get all fields as json


xxxlogiatxxx
 Share

Recommended Posts

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

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