@EAMann的回答是正确的,但已经有一个内置的WordPress函数用于获取所有注册的帖子类型:get_post_types
<?php
// hook into init late, so everything is registered
// you can also use get_post_types where ever. Any time after init is usually fine.
add_action( \'init\', \'wpse34410_init\', 0, 99 );
function wpse34410_init()
{
$types = get_post_types( [], \'objects\' );
foreach ( $types as $type ) {
if ( isset( $type->rewrite->slug ) ) {
// you\'ll probably want to do something else.
echo $type->rewrite->slug;
}
}
}