也许是吧?的优化版本my earlier solution.
add_filter( \'wp_dropdown_pages\', \'add_cpt_to_front_page_dropdown\', 10, 1 );
/**
* Adds CPTs to the list of available pages for a static front page.
*
* @param string $select Existing select list.
* @return string
*/
function add_cpt_to_front_page_dropdown( $select )
{
if ( FALSE === strpos( $select, \'<select name="page_on_front"\' ) )
{
return $select;
}
$cpt_posts = get_posts(
array(
\'post_type\' => \'YOUR_POST_TYPE\'
, \'nopaging\' => TRUE
, \'numberposts\' => -1
, \'order\' => \'ASC\'
, \'orderby\' => \'title\'
, \'posts_per_page\' => -1
)
);
if ( ! $cpt_posts ) // no posts found.
{
return $select;
}
$current = get_option( \'page_on_front\', 0 );
$options = walk_page_dropdown_tree(
$cpt_posts
, 0
, array(
\'depth\' => 0
, \'child_of\' => 0
, \'selected\' => $current
, \'echo\' => 0
, \'name\' => \'page_on_front\'
, \'id\' => \'\'
, \'show_option_none\' => \'\'
, \'show_option_no_change\' => \'\'
, \'option_none_value\' => \'\'
)
);
return str_replace( \'</select>\', $options . \'</select>\', $select );
}