Skip to content

Instantly share code, notes, and snippets.

@LeanSeverino1022
Last active November 18, 2024 16:16
Show Gist options
  • Save LeanSeverino1022/9cf9c53346e887a56f9d38844b67a7f4 to your computer and use it in GitHub Desktop.
Save LeanSeverino1022/9cf9c53346e887a56f9d38844b67a7f4 to your computer and use it in GitHub Desktop.
[Display post types] #wordpress
//Just copy paste the code in any php file and see the result
//Display ALL post types
$post_types = get_post_types();
foreach ( $post_types as $post_type ) {
echo '<p>' . $post_type . '</p>';
}
//Dispay all custom posts types
$args = array(
'public' => true,
'_builtin' => false,
);
$output = 'names'; // names or objects, note names is the default
$operator = 'and'; // 'and' or 'or'
$post_types = get_post_types( $args, $output, $operator );
foreach ( $post_types as $post_type ) {
echo '<p>' . $post_type . '</p>';
}
//you can also use a bunch of args to filter your result much. For details lists of args you can check the official WordPress Codex page: https://codex.wordpress.org/Function_Reference/get_post_types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment