• Hey!

    I have an array of id:s, both posts and pages. When i use

    $args = array('post__in' => $array_wit_ids);
    get_posts($args)

    I only get the posts. How can i get the pages as well?

    Yes, I’m sure i can use a loop and collect the arrays, but is’nt there any built in solution for this?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • You need to add the post_type argument to your query. See http://codex.wordpress.org/Function_Reference/WP_Query for a list of all available arguments.

    Thread Starter LinusPWR

    (@linuspwr)

    Ah. post_type ‘any’. Cool.

    Do i have to make a WPQuery()? I tried

    $args = array('post__in' => $array_wit_ids, 'post_type' => 'any');

    But it gave the same result.

    Do i have to make a WPQuery()?

    No. But you can use all of the same arguments in get_posts().

    'post_type' => 'any' should work but you could also try something like 'post_type' => array( 'post', 'page' )

    Thread Starter LinusPWR

    (@linuspwr)

    Thanks,

    But i get the same result with that one too. Only the posts. Ideas?

    Thread Starter LinusPWR

    (@linuspwr)

    Ah sorry. I’m just a bit stupid. It does work. But i only get 5 posts, it seems to be default.
    i had to add ‘posts_per_page’ => -1.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Get_posts and include pages’ is closed to new replies.