WordPress Snippet: Custom Post Types

Having a bit of a WordPress day today.

Let WordPress know we have a custom post type, and add a handler for metaboxes.

            add_action('init', 'create_pricelist_posttype');
            add_action("add_meta_boxes", "add_pricelists_metaboxes");

Create the post type, connect up our meta box handler.

            function create_pricelist_posttype(){
                register_post_type('pricelist',
                    // CPT Options
                    array(
                        'labels' => array(
                            'name' => __('Pricelists'),
                            'singular_name' => __('Pricelist')
                        ),
                        'public' => true,
                        'has_archive' => true,
                        'rewrite' => array('slug' => 'pricelist'),
                        'exclude_from_search'=>true,
                        'supports' => array('title', 'custom-fields', 'page-attributes'),

                    )
                );
            }

            function add_pricelists_metaboxes(){
                add_meta_box('wppo_products_prices', 'Products/Prices', 'wppo_products_prices_location', 'pricelist', 'normal', 'default');
                remove_meta_box('wpseo', 'pricelist', 'normal');
            }
A Door
Published