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"
 <option value="">
<?php echo esc_attr( __( 'Select page' ) ); ?></option> 
  foreach ( $pages as $pagg ) {
  	$option = '<option value="' . get_page_link( $pagg->ID ) . '">';
	$option .= $pagg->post_title;
	$option .= '</option>';
	echo $option;

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.