Halloween Sale 15% off Ends in See the plans
PHP

Product Catalog Post Type Without WooCommerce

Registers a "Products" catalog post type with Product Line categories for showcasing products when you do not sell online.

Don’t have WPIDE yet? Install it on your site

Code

// Names used in labels and URLs: edit to suit.
$wpide_type = array(
    'name'     => 'catalog_item', // Internal name: lowercase, max 20 characters, never change it once you have content.
    'singular' => 'Product',
    'plural'   => 'Products',
    'slug'     => 'products',
);

add_action( 'init', function () use ( $wpide_type ) {
    $s = $wpide_type['singular'];
    $p = $wpide_type['plural'];

    register_post_type( $wpide_type['name'], array(
        'labels'        => array(
            'name'                  => $p,
            'singular_name'         => $s,
            'menu_name'             => $p,
            'add_new_item'          => "Add New $s",
            'edit_item'             => "Edit $s",
            'new_item'              => "New $s",
            'view_item'             => "View $s",
            'view_items'            => "View $p",
            'all_items'             => "All $p",
            'search_items'          => "Search $p",
            'not_found'             => 'Nothing found.',
            'not_found_in_trash'    => 'Nothing found in Trash.',
            'archives'              => "$s Archives",
            'attributes'            => "$s Attributes",
            'insert_into_item'      => "Insert into $s",
            'uploaded_to_this_item' => "Uploaded to this $s",
            'item_published'        => "$s published.",
            'item_updated'          => "$s updated.",
        ),
        'public'        => true,
        'has_archive'   => $wpide_type['slug'],
        'rewrite'       => array( 'slug' => $wpide_type['slug'], 'with_front' => false ),
        'show_in_rest'  => true,
        'menu_icon'     => 'dashicons-products',
        'menu_position' => 43,
        'supports'      => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions' ),
    ) );

    register_taxonomy( 'product_line', $wpide_type['name'], array(
        'labels'            => array(
            'name'          => 'Product Lines',
            'singular_name' => 'Product Line',
            'menu_name'     => 'Product Lines',
            'all_items'     => 'All Product Lines',
            'edit_item'     => 'Edit Product Line',
            'view_item'     => 'View Product Line',
            'update_item'   => 'Update Product Line',
            'add_new_item'  => 'Add New Product Line',
            'new_item_name' => 'New Product Line Name',
            'search_items'  => 'Search Product Lines',
            'not_found'     => 'No product lines found.',
            'parent_item'   => 'Parent Product Line',
        ),
        'hierarchical'      => true,
        'public'            => true,
        'rewrite'           => array( 'slug' => 'product-line', 'with_front' => false ),
        'show_admin_column' => true,
        'show_in_rest'      => true,
    ) );
} );

Notes

Do not use alongside WooCommerce, which already registers the product post type; the name here is catalog_item.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.