/**
  * Save pages to WP keeping hierarchy
  * @param  $pages collection (array) of pages
  * @return null
  */
 public function savePagesToWP($pages, $save_content = false)
 {
     $pages = Taquito::arrayManipulate(function ($k, $v) use($save_content) {
         $id = $v->id;
         $post_content = null;
         if ($save_content) {
             $config = json_decode(base64_decode($v->config))[0];
             $elements = $config->elements;
             // find anything pertaining to body copy/post_content
             foreach ($elements as $e) {
                 if (preg_match('/body|content/i', $e->label)) {
                     $post_content = $e->value;
                 }
             }
         }
         return array($id => array('name' => $v->name, 'parent_id' => $v->parent_id, 'post_content' => $post_content));
     }, $pages);
     foreach ($pages as $k => $page) {
         $temp_array = array('post_title' => wp_strip_all_tags($page['name']), 'post_status' => 'publish', 'post_author' => 1, 'post_type' => 'page');
         if ($save_content && strlen($page['post_content'])) {
             $temp_array['post_content'] = $page['post_content'];
         }
         $id = wp_insert_post($temp_array);
         $pages[$k]['post_id'] = $id;
     }
     foreach ($pages as $k => $page) {
         if ($page['parent_id'] === 0) {
             continue;
         }
         wp_update_post(array('ID' => $page['post_id'], 'post_parent' => $pages[$page['parent_id']]['post_id']));
     }
 }
    exit;
}
// the number of posts to create
$n = $_GET['number'];
// the post type must be associated with a Taco class
// e.g. class Post extends \Taco\Post {...
$post_type = $_GET['post_type'];
// initialize a helper class of the post type so we can get the fields
$helper = new $post_type();
// find taxonomies and terms based on the post ype
$taxonomies = method_exists($post_type, 'getTaxonomies') ? $helper->getTaxonomies() : array();
if (\AppLibrary\Arr::iterable($taxonomies)) {
    $taxonomies_terms = Taquito::arrayManipulate(function ($k, $tax_name) {
        $terms = get_terms($tax_name, array('hide_empty' => false));
        if (\AppLibrary\Arr::iterable($terms)) {
            return array($tax_name => \AppLibrary\Collection::pluck($terms, 'term_id'));
        }
        return array($k, $tax_name);
    }, $taxonomies);
}
$fields = $helper->getFields();
if (!array_key_exists('created_for_testing', $fields)) {
    echo '<b>Error:</b> A field named "created_for_testing"' . 'must be added to the getFields method for this post type\'s class.';
    exit;
}
unset($helper);
// based on the number in $_GET, create and iterate
for ($i = 0; $i < $n; $i++) {
    $faker = Faker\Factory::create();
    $faker->addProvider(new Faker\Provider\Resource($faker));
    $instance = new $post_type();