Codex tools: Log in
Contents |
Returns the registered post types as found in $wp_post_types.
<?php get_post_types( $args, $output, $operator ) ?>
Some of these include:
The call to get post types returns the registered post types.
<?php $post_types=get_post_types(); ?>
<?php
$post_types=get_post_types('','names');
foreach ($post_types as $post_type ) {
echo '<p>'. $post_type. '</p>';
}
?>
<?php
$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>';
}
?>
This example uses the 'object' output to retrieve the post type called 'property':
<?php
$args=array(
'name' => 'property'
);
$output = 'objects'; // names or objects
$post_types=get_post_types($args,$output);
foreach ($post_types as $post_type ) {
echo '<p>' . $post_type->name . '</p>';
}
?>
Be careful when retrieving "public" custom post-types that were registered using the register_post_type() function: the inputs to the register_post_type function are not intelligently processed, so if you verbosely set options for publicly_queriable, show_ui, show_in_nav_menus, and exclude_from_search, this is NOT considered equivalent to setting the public option and querying for public post-types will not yield results that were defined with the equivalent explicit arguments. See bug 18950.
WordPress builtin post types:
get_post_types() is located in wp-includes/post.php.
Post Types: register_post_type(), add_post_type_support(), remove_post_type_support(), post_type_supports(), post_type_exists(), set_post_type(), get_post_type(), get_post_types(), get_post_type_object(), get_post_type_capabilities(), get_post_type_labels(), is_post_type_hierarchical(), is_post_type_archive(), post_type_archive_title()