Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a CPT called 'vacancies' here is the code that registers it:

function register_cpt_vacancy() {
    $args = array('labels' => $labels, 'hierarchical' => false, 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions'), 'taxonomies' => array('departments'), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'show_in_nav_menus' => true, 'publicly_queryable' => true, 'exclude_from_search' => false, 'has_archive' => true, 'query_var' => true, 'can_export' => true, 'rewrite' => true, 'capability_type' => 'post');
    register_post_type('vacancy', $args);
}

In a template footer I'm trying to do this:

wp_list_pages('post_type=vacancy');

Which - from reading the docs I thought would work.

Is there another way to do this besides creating my own query and menu styles? This list of vacancies is appearing as a menu between two other wp menus called with wp_nav_menu so I would like it to be in a list structure like they are.

Any help or suggestions for different approaches welcomed :)

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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 ) : ?>
        <li><a href="<?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.

share|improve this answer
    
Brilliant mate, thanks for the explanation, and workarounds! –  Mere Development Jul 26 '12 at 12:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.