I am trying to retrieve the post types and put them into an array with their slug being the index and their label being the value. When I print_r( get_post_types() );
it returns the proper array with data, but when I try to use it like below, it returns null.
function get_posttype_list() {
$pt_list = [];
$post_types = get_post_types( array( 'public' => true ) );
foreach( $post_types as $pt ) {
$pt_list[ $pt->name ] = $pt->labels->singular_name;
}
}
print_r( get_post_types( array( 'public' => true )));
does this return an array?$pt_list
however nothing is done with this variable and there is noreturn
statement, is your code incomplete? Can you update it with the rest of the function? How are you checking that it returnsnull
and where is the code running?