0

this is driving me crazy... I have an admin plugin page that lists pages for a wordpress website. I'm trying to list all the pages using get_pages() but for some reason once pages are published they don't show up anymore - when I use get_posts they show up, but the new draft pages don't :(

Here is the code.. please help

//this only displays the new draft pages - once published pages don't show up here
$args = array('post_status' => 'draft, publish');
$pages = get_pages($args);                                                   
foreach ( $pages as $page ) { some html code that displays the page title }

//this piece of code will return all pages onces they were published, 
//even if 'unpublished' later - but will not return new draft pages
global $post;
$args2 = array( 'numberposts' => 50, 'post_status' => 'publish, draft');
$myposts = get_posts( $args2 );
foreach( $myposts as $post ) {
    setup_postdata($post); 
    ... some HTML code to display the pages
}

what's going on?

3
  • Have you tried removing the spaces after the commas in your post_status args?
    – mrwweb
    Aug 3, 2012 at 19:42
  • just tried that - still getting different results here. BTW I'm setting up multisite (can that have something to do with this?)
    – OS.
    Aug 3, 2012 at 19:46
  • you are passing array wrong way, see my answer.
    – amit
    Aug 3, 2012 at 19:50

1 Answer 1

1

You are passing the array for post_status wrong way, Here I updated your code with correction.

To show List of pages

//To display list of pages
$args = array('post_status' => array('drafts', 'publish'));
$pages = get_pages($args);                                                   
foreach ( $pages as $page ) { 
    // some html code that displays the page title 
}

To show List of Posts

// To display list of posts
global $post;
$args2 = array('numberposts' => 50, 'post_status' => array('drafts', 'publish'));
$myposts = get_posts( $args2 );
foreach( $myposts as $post ) {
    setup_postdata($post); 
    //... some HTML code to display the pages
}

Note -

It appears you've got confused with terms posts and pages.

  • get_pages() function will return the pages, not the posts
  • get_posts() function will return the posts
1
  • thanks amit - that actually doesn't work. I found out that I was not saving page as PAGE when publishing, it defaulted to POST
    – OS.
    Aug 3, 2012 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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