Created
January 11, 2018 07:15
-
-
Save sonicpunk/0d02ed86fc5870f43cfe6bfb49a03385 to your computer and use it in GitHub Desktop.
migrateContent to JSON for importing to another site
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$parents = explode(',',$modx->getOption('parents',$scriptProperties,'11,10,12,13,14')); | |
$parents = array_unique($parents); | |
$output = array(); | |
foreach ($parents as $parent) { | |
$childrenOutput = array(); | |
$children = $modx->getCollection('modResource', array('parent'=>$parent)); | |
foreach ($children as $child) { | |
$tvOutput = array(); | |
$tvs = $child->getTemplateVars(); | |
foreach ($tvs as $tv){ | |
$tvOutput[] = $tv->toArray(); | |
} | |
$childrenOutput[$child->get('id')] = array( | |
'pagetitle'=>$child->get('pagetitle'), | |
'longtitle'=>$child->get('longtitle'), | |
'content'=>$child->get('content'), | |
'description'=>$child->get('description'), | |
'tvs' => $tvOutput | |
); | |
} | |
$output[$parent] = $childrenOutput; | |
} | |
return json_encode($output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Throw this in a snippet and add the snippet to a resource and call up the resource in the frontend to generate your json