Skip to content

Instantly share code, notes, and snippets.

@ann71727
Last active October 28, 2017 15:05
Show Gist options
  • Save ann71727/158bf5fdab76a791da9ebe3e986474db to your computer and use it in GitHub Desktop.
Save ann71727/158bf5fdab76a791da9ebe3e986474db to your computer and use it in GitHub Desktop.
List All Post Type Names
<?php
/*
* List All Post Type Names
* https://v123.tw
*/
function v123_get_all_post_type_names(){
global $wp_post_types;
$posttypes = array_keys( $wp_post_types );
// exclude_post_type 排除的 Post Type name
$exclude_post_type = array("attachment","nav_menu_item","customize_changeset","revision");
foreach ( $posttypes as $posttype ):
if ( in_array($posttype, $exclude_post_type) ) continue;
$posttype_names[ $posttype ] = $posttype;
endforeach;
print_r($posttype_names);
}
add_action('init','v123_get_all_post_type_names');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment