How Do I Show Custom Post Type in WordPress?
Custom post types are one of the most powerful features of WordPress, and allow you to create custom templates and content types for your site. To create a custom post type, you first need to create a new file in your WordPress directory called custom.
php . This file will hold all of the code for your custom post type.
Inside of custom.php , you’ll need to add the following lines of code:
/** * The Custom Post Type Template */ define( ‘WP_POST_TYPE’ , ‘custom’ ); /** * The Custom Post Type Name */ define( ‘WP_POST_TYPE_NAME’ , ‘my_custom_post_type’ );
Next, you’ll need to define the custom post type inside of the wp_post_types() function. The following code will create a new custom post type called “my_custom_post_type”:
/** * Get the list of posts of the given type * * @param string $type The post type to query */ function wp_post_types( $type = ‘custom’ ) { $post_types = array( ‘my_custom_post_type’ ); $args = array( ‘tax_query’ => array( ‘tax_query’ => array( ‘field’ => ‘post_type’, ‘operator’ => ‘IN’, ‘column’ => ‘slug’, ‘cache_value’ => false, ‘supports’ => array( ‘title’ ), ), ), ), ); return $post_types; }
Now that your custom post type is defined, you’ll need to add some custom content to it. To do this, you’ll need to add a file called content.
php to your WordPress directory. This file will contain the content for your custom post type.
Inside of content.php , you’ll need to add the following lines of code:
/** * The Custom Post Type’s Content Template */ define( ‘WP_POST_TYPE_CONTENT_TEMPLATE’ , ‘my_custom_post_type’ ); /** * The Custom Post Type’s Content */ require_once( ‘./custom.php’ );
Next, you’ll need to add a template for your content. To do this, you’ll need to add the following line of code to your content.php file:
Finally, you’ll need to add some content to your custom post type. To do this, you’ll need to add the following lines of code to your content.php file:
That’s all you need to do to create and manage a custom post type in WordPress. As long as you have a file called custom.
php in your WordPress directory, and the content.php file in your WordPress directory is configured correctly, you’ll be able to create and manage custom post types easily.