How to create a custom post in wordpress

Creating an ecommerce website using WordPress is a relatively simple and affordable process.

To create a custom post type in WordPress, you can use the register_post_type() function. This function allows you to create a new post type and specify its labels, options, and capabilities.

Here’s an example of how you can use register_post_type() to create a custom post type called “Books”:

function create_book_post_type() {
    register_post_type( 'book',
        array(
            'labels' => array(
                'name' => 'Books',
                'singular_name' => 'Book',
                'add_new' => 'Add New',
                'add_new_item' => 'Add New Book',
                'edit_item' => 'Edit Book',
                'new_item' => 'New Book',
                'view_item' => 'View Book',
                'search_items' => 'Search Books',
                'not_found' => 'No books found',
                'not_found_in_trash' => 'No books found in Trash',
                'parent_item_colon' => '',
                'menu_name' => 'Books',
            ),
            'public' => true,
            'has_archive' => true,
            'menu_position' => 5,
            'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
            'taxonomies' => array( 'category', 'post_tag' ),
            'rewrite' => array( 'slug' => 'books' ),
        )
    );
}
add_action( 'init', 'create_book_post_type' );

This code creates a new function called create_book_post_type(), which registers a new post type called “book” using the register_post_type() function. It specifies a number of labels for the post type, such as the name, singular name, and various labels for the post type’s admin menu. It also sets the public and has_archive options to true, which makes the post type visible to visitors and enables an archive page for the post type.

The WordPress handbook: expert guidance straight from the experts!

Grow Your Following!

Gain More Email Subscribers with Bloom, an Email Opt-In Plugin for WordPress.

Get Bloom today

Bloom

The only creative subscription you need

Individual plan – From €14.50/m

Start a 7 day free trail

Already an Envato member? Sign in here.

*All Individual plans include a 7-day free trial with unlimited access for new customers; then chosen plan price applies. Cancel any time.

  • Millions of creative assets
  • Unlimited downloads
  • Simple commercial licensing
  • Cancel any time
Envato elements
Created using items from Photos, Graphics and Fonts

The menu_position option specifies the position of the post type’s menu item in the admin menu, and the supports option specifies which features are enabled for the post type (e.g., title, editor, author, etc.). The taxonomies option specifies which taxonomies (e.g., categories and tags) are enabled for the post type, and the rewrite option specifies the permalink structure for the post type’s archive page.

Finally, the add_action() function hooks the create_book_post_type() function to the init action, which means that it will be executed when WordPress initializes.

This code creates a new post type called “Books” with the following features:

  • Visible to visitors and searchable on the front end of the site
  • An archive page at /books/ that displays all the books
  • The ability to add a title, editor, author, thumbnail, excerpt, and comments to each book
  • The ability to assign categories and tags to each book

I hope this helps! Let me know if you have any questions or need further assistance.

The best plugins for WordPress

In a world of WordPress plugins, be iconic – choose the best, be the best.

WP Forms plugin

WP Forms

The world’s best drag & drop WordPress forms.

Advanced Custom Fields plugin

ACF

Advanced Custom Fields Plugin
for WordPress

RankMath Seo plugin

RankMath SEO

Best Free WordPress SEO Tools
in 2023