0

Trying to get all posts (with all I mean all pages, posts and posts from custom post types).

Is this possible? The documentation says I can only pass a string as post_type so how can I get all pages and custom post types?

Example where custom post type is called project

$args = array(
    'exclude'      => $inclPages,
    'post_type'    => 'pages,project',
    'title_li'     => __(''),
    'sort_column'  => 'menu_order'
);
$pages = get_pages( $args );

Any advice would be appreciated

2 Answers 2

6

get_pages does not work with posts or post types that is not hierarchical like pages, so if your post type is hierarchical like posts, it would not work

This function can also retrieve other post types using the 'post_type' parameter, but the type must be hierarchical like pages, or the function will return false.

If you need all post types to be returned, ie all post, page and custom post types, just pass any to post_type in either get_posts or WP_Query, the choice is up to you

2
  • "any" did the trick! thanks a lot! also for the question edit.. my english is getting better :)
    – caramba
    Sep 16, 2014 at 9:32
  • My pleasure. Glad it worked :-) Sep 16, 2014 at 9:38
8

Why not use WP_Query instead. Like this.

$args = array(
    'post__not_in' => $inclPages,
    'post_type'    => array( 'page', 'project' )
    'orderby'      => 'menu_order'
);
$pages = new WP_Query ( $args );

WP_Query accepts wide range of parameters. And also post_type array.

1
  • never used WP_Query before
    – caramba
    Sep 16, 2014 at 9:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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