There is a pretty simple way to query outside the loop using get_posts. Setting post_status => 'any'
could net you all.
The code below queries posts, pages and attachments. The loops through and outputs them all to an unordered list.
$pages = get_posts( array(
'post_type' => 'page',
'post_status' => 'any',
'numberposts' => -1,
));
$posts = get_posts( array(
'post_type' => 'post',
'post_status' => 'any',
'numberposts' => -1,
));
$attachments = get_posts( array(
'post_type' => 'attachment',
'post_status' => 'any',
'numberposts' => -1,
));
echo '<ul>';
echo '<li><h2>POSTS</h2></li>';
foreach ( $posts as $post ) {
$link = get_the_permalink ( $post->ID );
echo "<li>{$post->post_type} - {$post->post_status} - {$post->ID} - <a target=\"_blank\" href=\"{$link}\">{$post->post_title}</a></li>";
}
echo '<li><h2>PAGES</h2></li>';
foreach ( $pages as $post ) {
$link = get_the_permalink ( $post->ID );
echo "<li>{$post->post_type} - {$post->post_status} - {$post->ID} - <a target=\"_blank\" href=\"{$link}\">{$post->post_title}</a></li>";
}
echo '<li><h2>ATTACHMENTS</h2></li>';
foreach ( $attachments as $post ) {
$link = get_the_permalink ( $post->ID );
echo "<li>{$post->post_type} - {$post->post_status} - {$post->ID} - <a target=\"_blank\" href=\"{$link}\">{$post->post_title}</a></li>";
}
echo '</ul>';
If you really want to grab it all:
$any = get_posts( array(
'post_type' => 'any',
'post_status' => 'any',
'numberposts' => -1,
));