Custom post types can only be registered on the init
hook. So if you’re trying to get the post types before the init
hook, you will only ever get the built-in ones.
To get custom post types, you need to use a hook after init
, or later on init
than the custom post types were registered.
function wpse_func() {
$args = array(
'public' => true,
'_builtin' => false,
];
$post_types = get_post_types( $args );
}
add_action( 'init', 'wpse_func', PHP_INT_MAX );
//* Or
add_action( 'wp_loaded', 'wpse_func' );