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 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:
/books/
that displays all the booksI hope this helps! Let me know if you have any questions or need further assistance.
In a world of WordPress plugins, be iconic – choose the best, be the best.
The world’s best drag & drop WordPress forms.
Advanced Custom Fields Plugin
for WordPress
Best Free WordPress SEO Tools
in 2023