Special Post Type Functions WordPress


WordPress features many different post type
specific functions to make working with custom post
types that much easier. In this section, you will review some of the more common functions you
might use when building your websites.
To return a list of all registered post types in WordPress, you’ll use the get_post_types()function.
<?php get_post_types( $args, $output, $operator ); ?>
This function accepts three optional parameters:
1.  $args— An array of arguments to match against the post type.
2.  $output— The type of output to return, either namesor objects. Defaults to names.
3.  $operator— Operator to use with multiple $args. Defaults to and.
Using the get_post_types()function, use the following to return a list of all custom post types
registered in WordPress:
$args = array(
'public' => true,
'_builtin' => false
);
$post_types = get_post_types( $args, 'names', 'and' );
foreach ( $post_types as $post_type ) {
echo '<p>'. $post_type. '</p>';
}
As shown in the preceding code, you’ll set two arguments in the $argsarray: publicand _
builtin. The publicargument will only return custom post types that are set to be publicly
viewable. The _builtinargument is set to false, which will not return default post types like posts
and pages. You also set the $outputargument to return just the post type name, and the $operator
argument to use “and” for the multiple $argsyou passed to the function.
To determine what post type a piece of content is, you’ll use the get_post_type()function:
Related Posts:
  • how to Debugging Errors Wordpress Debugging errors in WordPress can be made easier using the  WP_DEBUGoption. Enabling WP_DEBUG displays WordPress errors on the screen, rather than suppressing those errors with a white screen. To enable WP_DEBUG, ju… Read More
  • Abstract data type In programming, a data set defined by the programmer in terms of the information it can contain and the operations that can be performed with it. An abstract data type is more generalized than a data type constr… Read More
  • Essential WordPress Plugins One of the great things about WordPress is that you can extend it with all kinds offunctionality with WordPress Plug-ins. There are hundreds of plugins that you can use,but here I’d like to list a few of the essential ones.I… Read More
  • WordPress is a popular piece of blog software WordPress is a popular piece of blog software. It comes in two flavors. wordpress.org is the home of the WordPress publishing platform  itself, where you can download installation files, search the forums for help, a… Read More
  • seo tips for wordpress 1>Add a WordPress SEO plugins and  then Choose a SEO-friendly WordPress theme or createWordPress theme that  contains all the HTML and CSS code your site. 2>search engines  likes all that great content. … Read More
  • Special Post Type Functions WordPress WordPress features many different post type specific functions to make working with custom post types that much easier. In this section, you will review some of the more common functions you might use when building your w… Read More
  • WordPress’s SEO advantages Using WordPress for your blogging platform or content management system,comes with some advantages, including that WordPress was designed tofunction well with search engines. Search engines can crawl the source codeof a Word… Read More
  • WordPress Content Management System Blogging systems have their roots in simple content  management operations: Create a post, persist it in stable storage such as a filesystem or database, and display the formatted output based on some set of temporal … Read More