Example #1
0
 public static function convert_nesting_to_indentation($nested_array, $indent_key, $children_key = 'children', $depth = 0)
 {
     $i = 0;
     $indented_array = array();
     foreach ($nested_array as $index => $value) {
         if (isset($value->{$children_key})) {
             $newpart = CACIE_Arrays::convert_nesting_to_indentation($value->{$children_key}, $indent_key, $children_key, $depth + 1);
             unset($value->{$children_key});
             $value->{$indent_key} = str_repeat('-', $depth) . $value->{$indent_key};
             $indented_array[] = $value;
             $indented_array = array_merge($indented_array, $newpart);
         } else {
             $indented_array[] = $value;
         }
     }
     return $indented_array;
 }
Example #2
0
 /**
  * Get post parent columns
  *
  * @since 1.0
  *
  * @return array Parent post options ([post ID] => [post title])
  */
 public function get_post_parent_options()
 {
     $options = array();
     $posts_query = new WP_Query(array('post_type' => $this->storage_model->key, 'posts_per_page' => -1));
     if ($posts_query->have_posts()) {
         $nestedposts = CACIE_Arrays::array_nest($posts_query->posts, 0, 'post_parent', 'ID', 'cacie_children');
         $indentedposts = CACIE_Arrays::convert_nesting_to_indentation($nestedposts, 'post_title', 'cacie_children');
         foreach ($indentedposts as $post) {
             $options[$post->ID] = $post->post_title;
         }
     }
     return $options;
 }