WordPress get list of private pages

Needed a list of private pages for a widget I was creating, here’s how you get them:

$pages = get_pages(array(  
   'post_status' => 'private'
));

you can also get a list of “public” and “private” pages together like this:

$pages = get_pages(array(  
   'post_status' => 'publish,private'
));

And once you have that list you can process it, like putting it into a drop down box (from codex example):

<select name="page-dropdown"
 onchange='document.location.href=this.options[this.selectedIndex].value;'> 
 <option value="">
<?php echo esc_attr( __( 'Select page' ) ); ?></option> 
 <?php 
  foreach ( $pages as $pagg ) {
  	$option = '<option value="' . get_page_link( $pagg->ID ) . '">';
	$option .= $pagg->post_title;
	$option .= '</option>';
	echo $option;
  }
 ?>
</select>

Handy if you need a list of public and private pages in the backend for some reason.  

Leave a Reply

Your email address will not be published. Required fields are marked *