get_page_by_title( $title, [$output = \'object\'], [$post_type = \'page\'] )
存在就是为了这个目的。我现在在我的一个项目中使用它来显示侧边栏中特定页面的所有附件:
if ( $oPage = get_page_by_title(\'Proudly Supporting...\') ) {
$children = get_posts(array(
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'numberposts\' => 3,
\'post_status\' => null,
\'post_parent\' => $oPage->ID, /* Using the Page ID */
\'orderby\' => \'rand\',
));
if ( $children ) {
/* Do something with the children */
}
}