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 ultimate WordPress page builder

Lifetime Access – $249 (1-time)

Buy the Divi theme now

Divi is used by 974,872 customers who have given it over 23,000 5-star reviews. Why? Firstly, it’s the best (and easiest) way to build a WordPress website. Secondly, it’s cheaper than every competitor while offering unlimited website usage.

  • Unlimited Use
  • Simple Pricing
  • Constant Updates
  • Rock Solid Security
  • 24/7 Premium Support

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