= 3.8) { $title = '' . __('Edit Content', 'bs_abep') . ''; $img = ''; } else { $title = '' . __('Edit Content', 'bs_abep') . ''; $img = '_no_dashicon'; } $admin_url = admin_url(); // Add the Parent link. $wp_admin_bar->add_menu( array( 'title' => $title, 'href' => false, 'id' => 'bs_abep_links'.$img, )); $args = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_status' => 'publish', 'posts_per_page' => -1, ); foreach ($options as $post_type => $nice_name){ $args['post_type'] = $post_type; // Filter the args now if (has_filter('bs_abep_query_args')) { $args = apply_filters('bs_abep_query_args', $args); // Let's reset the post type in case the user inadvertently changed it - there's really no reason to change it. $args['post_type'] = $post_type; } $bs_abep_query = get_posts( $args ); echo '
' . print_r(count($bs_abep_query), true) . ''; if ( !empty($bs_abep_query) ) : if ( is_post_type_hierarchical($post_type) ) { // Sort them into a hierarchical list here //echo '
' . print_r($bs_abep_query, true) . ''; //$bs_abep_query = my_sort_posts( $bs_abep_query ); } // We have some posts, let's add a parent menu $wp_admin_bar->add_menu( array( 'title' => $nice_name, 'href' => $admin_url . 'edit.php?post_type=' . $post_type, 'id' => $post_type, 'parent' => 'bs_abep_links'.$img )); foreach ($bs_abep_query as $post) { if ($post->post_parent != 0){ $label = ' – '.ucwords($post->post_title); $parent_id = $post->post_parent; if ( ( count( get_post_ancestors($parent_id) ) ) >= 1 ) { $label = ' '.$label; } } else { $label = ucwords($post->post_title); } $url = get_edit_post_link($post->ID); $wp_admin_bar->add_menu( array( 'title' => $label, 'href' => $url, 'id' => $post->ID, 'parent' => $post_type )); } endif; } } // Add each level's child posts to the result list, in order function recursively_flatten_list( $list, &$result ) { foreach( $list as $node ) { $result[] = $node['post']; if( isset( $node['children'] ) ) recursively_flatten_list( $node['children'], $result ); } } function my_sort_posts( $posts ) { $refs = $list = array(); echo '
' . print_r(count($posts), true) . ''; foreach( $posts as $post ) { $thisref = &$refs[$post->ID]; $thisref['post'] = $post; if( $post->post_parent == 0) $list[$post->ID] = &$thisref; else $refs[$post->post_parent]['children'][$post->ID] = &$thisref; } // Create single, sorted list $result = array(); recursively_flatten_list( $list, $result ); return $result; } function bs_abep_activation_callback() { $options = get_option('bs_abep_settings', array()); $default = array( 'types' => array( 'page' => 'Pages', ), ); if ( empty($options) ) { update_option('bs_abep_settings', $default ); } } add_filter('bs_abep_query_args', 'temp_filter', 10, 1); function temp_filter( $args ) { $args['orderby'] = 'name'; } ?>