Creating a navigation menu of all posts of a custom post type and their children posts?

Question

I have a drop down menu that displays a link (the permalink) to all of the posts of a custom post type (county) and would simply like to display their children too this is the code I have so far but get_children is not working…

<ul>
    <?php $menu = new WP_Query( array(
        'post_type' => 'county',
        'post_status' => 'publish',
        'posts_per_page' => -1,
        'order' => 'desc'
    ) );
    while ( $menu->have_posts() ) : $menu->the_post(); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <ul>
            <?php get_children(); ?>
        </ul>
    </li>
    <?php endwhile; ?>
</ul>

this is the code that allows me to assign on custom post type as the parent of another

function show_parent_metabox() {
    parent_select('county');
}

function parent_select ($parent_type) {
    global $post;
    global $wpdb;
    $query = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = '{$parent_type}'         AND post_status = 'publish' ORDER BY post_title";
    $results = $wpdb->get_results($query, OBJECT);
    echo '<select name="parent_id" id="parent_id">';
    echo '<option value = "">None</option>';
    foreach ($results as $r) {
        echo '<option value="', $r->ID, '"', $r->ID == $post->post_parent ? '    selected="selected"' : '', '>', $r->post_title, '</option>';
    }
    echo '</select>';
}
0
, , jonhodson1984 8 years 2014-01-05T07:13:21-05:00 0 Answers 86 views 0

Leave an answer

Browse
Browse