wp_list_pages not showing cpt as I expected

On the wp_list_pages docs, it states that:

If a given custom post type is hierarchical in nature, then
wp_list_pages() can be used to list the member of that custom post
type.

Based on your code, the CPT that you are attempting to use with wp_list_pages() is not hierarchical.

Therefore, two solutions:

1. Change the Custom Post Type

Make your post type hierarchical (like pages) by setting 'hierarchical' => true and 'capability_type' => 'page'.

2. Use a Different Function

I recommend using something like:

$vacancy_menu = get_posts( 'post_type=vacancy' );

if( $vacancy_menu ) : ?>
    <ul>
    <?php foreach( $vacancy_menu as $menu_item ) : 
      setup_postdata( $menu_item );?>
        <li><a href="https://wordpress.stackexchange.com/questions/59033/<?php the_permalink(); ?>" title="Go to <?php the_title(); ?>"> <?php the_title(); ?></a></li>
    <?php endforeach; ?>
    </ul>
<?php endif; ?>

If you’d like, this could easily be setup as a function to create your own “wp_list_posts()” or set to match the html of wp_nav_menu().

Also, be sure to check out this example from CSS Tricks as well for a similar explanation with info on how to apply “current” classes to the links.

Leave a Comment