get_posts fails to return drafts and published posts
-
Hi,
I can’t get the get_posts function to return both drafts and published posts. This is my code:$args = array( 'numberposts' => NULL, 'offset' => 0, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => 'post', 'post_status' => array('drafts', 'publish') ); $Post_Array = get_posts($args);
If I run the function twice and combine the resulting arrays it works, but then the orderby is wrong because it just adds the second array to the end of the first array. Here is the code:
$args = array( $args = array( 'numberposts' => NULL, 'offset' => 0, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => 'post', 'post_status' => 'draft' ); $Post_Array1 = get_posts($args); $args = array( 'numberposts' => NULL, 'offset' => 0, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => 'post', 'post_status' => 'publish' ); $Post_Array2 = get_posts($args); $Post_Array = array_merge((array)$Post_Array1, (array)$Post_Array2);
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘get_posts fails to return drafts and published posts’ is closed to new replies.