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.

In my wordpress enviroment, I have a number of pages, and I also have a custom post type called casestudy. I have setup a page-clients.php that has some of it's own content on, I then use the query_posts() function to pull in all the posts with the post type casestudy.

When viewing a single case study I wanting to show a nav, this nav needs to contain the links to pages, clients, and case study and underneath case studies I want to add all the posts that are of the custom post type 'casestudy' so far I have following,

<?php wp_list_pages(array('include' => '154, 136', 'title_li' => '', 'sort_column' => 'ID', 'sort_order' => 'DESC', 'depth' => '1')); ?>

How can I lists all the casestudy posts also, can it be done with wp_list_pages()

share|improve this question

1 Answer 1

up vote 1 down vote accepted

The wp_list_pages() function uses get_pages(), which accepts a post_type argument-array key, so you can use that same argument array key in `wp_list_pages():

<?php
wp_list_pages( array(
    'post_type' => 'casestudy'
) );
?>

Unfortunately, it looks like the post_type value must be a string, rather than an array (that is, if I'm reading the source correctly); which means that wp_list_pages() can only handle one post-type at a time. If you need to list all in one menu, you could try concatenating them:

<?php

$pagelist = wp_list_pages( array( 
    'include' => '154, 136', 
    'title_li' => '', 
    'sort_column' => 'ID', 
    'sort_order' => 'DESC', 
    'depth' => '1'
    'echo' => false
) );

$casestudylist = wp_list_pages( array(
    'post_type' => 'casestudy',
    'title_li' => '',
    'echo' => false
) );

$concatenatedlist = $pageslist . $casestudylist;
?>

<ul>
<?php echo $concatenatedlist;
</ul>

Codex references:

share|improve this answer
    
many thanks the second wp_list_pages is returning false though, even thouse casestudy is post type and has posts belonging too it –  sico87 Jul 26 '11 at 15:55
    
Did you copy/paste the code? Check for a syntax error, that I've since corrected. I left off the comma after 'post_type' => 'casestudy' in the argument array. –  Chip Bennett Jul 26 '11 at 16:39
    
@Chip Bennett, thanks for the code and explanation. Is there another way to display wp pages and Custom Post Types together that are added dynamically (meaning that I don't know their name)? Maybe there is another function that can handle it instead of wp_list_pages? Thanks! –  dashaluna Nov 9 '11 at 10:09

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.