有一种非常简单的方法可以使用get_posts. 背景post_status => \'any\'
可以把你们都抓起来。
下面的代码查询帖子、页面和附件。循环并将它们全部输出到无序列表中。
$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>\';
如果你真的想抓住一切:
$any = get_posts( array(
\'post_type\' => \'any\',
\'post_status\' => \'any\',
\'numberposts\' => -1,
));