• Resolved kerricklong

    (@kerricklong)


    Hello there!

    I would like to list pages like wp_list_pages() does, but I want to only list pages that have subpages.

    Example:
    Pages I have published:
    -Automotive
    –Repair
    –Detailing
    -Food
    -Fun
    -Retail
    –Stores
    –Dealers
    Pages I do not want shown:
    -Food
    -Fun

    is this possible in any way? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Don’t know if it’s the best way….

    <?php
    $parents = $wpdb->get_col("SELECT DISTINCT post_parent FROM $wpdb->posts WHERE $wpdb->posts.post_parent != 0  AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish'");
    $parent_ids = implode($parents,', ');
    $children = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent IN ($parent_ids)  AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish'");
    $pages = array_merge((array)$parents, (array)$children);
    wp_list_pages('include=' .implode(",", $pages));
    ?>

    Thread Starter kerricklong

    (@kerricklong)

    It may not be the best way (I have no idea), but it worked like a charm! Thanks a bunch! ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List only pages with children?’ is closed to new replies.