You are not seeing or that your function (test_get_post_types
) is not returning the custom post types because if you look at the Carbon Fields source code, carbon_fields_register_fields
is run by Carbon_Fields\Loader\trigger_fields_register()
which is hooked on init
with the priority 0
. (See lines 113 and 44 in carbon-fields/core/Loader/Loader.php
)
So that means, by the time your lnpa_attach_theme_options
function runs (i.e. called via the carbon_fields_register_fields
hook), those custom post types (“book”, “movie”, etc.) have not yet been registered because despite custom post types are commonly registered during init
, the priority would not be 0
in normal cases.
Therefore, instead of passing the output of your test_get_post_types
function, you should pass the function as a callable to the add_options()
function, like so:
Field::make('select', 'ggg_post_type', __('Select post type.'))
// Pass a callable, i.e. a function that is called later.
->add_options( array( $this, 'test_get_post_types' ) )
See the Carbon Fields documentation for more/other information.