Get an array of post type name
-
Currently on my project I need an array of custom post type name. I want my array like this,
array( 'post' => 'post', 'page' => 'page', 'attachment' => 'attachment' );
and my code like this to retrieve an array that I expect:
private function post_type_name_array() { $types_array = array(); foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $post_types ) { $type_array[] = $post_types->name; $types_array = $type_array; } return $types_array; }
but the output I get is like this
array( 0 => 'post', 1 => page, ... );
Any idea?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Get an array of post type name’ is closed to new replies.