How do i register multiple custom post types
-
Hi,
I have decided to create my first plugin(Foxware Recipe), iv already learnt a little bit from working with WordPress for about a year now and i have the basic understandings of different things in WordPress and what they are for (or have become familiar with looking it up in the codex) and the structure of the DB.
I’m using boilerplate, and i have successfully registered my first custom post type, but now i can’t figure out how to register a second post type.
The plugin im trying to create is a recipe costing program where a user can create A recipe and add ingredients to it, they can also add a supplier and place a cost for each ingredient in the supplier_meta table.
So i need to create 3 custom post types, Recipe, Ingredient and Supplier. I prefer to use a full post type for the ingredient instead of a taxonomy because the ingredient will have data attached to it like unit measure, qty, alternative ingredients etc…
So my question is, how do i create 3 custom post type? I have placed the code below into my plugin-name.php file in my plugin folder
// If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { die; } /** * The code that runs during plugin activation. */ require_once plugin_dir_path( __FILE__ ) . 'includes/class-foxware_recipe-activator.php'; /** * The code that runs during plugin deactivation. */ require_once plugin_dir_path( __FILE__ ) . 'includes/class-foxware_recipe-deactivator.php'; /** This action is documented in includes/class-foxware_recipe-activator.php */ register_activation_hook( __FILE__, array( 'foxware_recipe_Activator', 'activate' ) ); /** This action is documented in includes/class-foxware_recipe-deactivator.php */ register_deactivation_hook( __FILE__, array( 'foxware_recipe_Deactivator', 'deactivate' ) ); /** * The core plugin class that is used to define internationalization, * dashboard-specific hooks, and public-facing site hooks. */ require_once plugin_dir_path( __FILE__ ) . 'includes/class-foxware_recipe.php'; /** * Begins execution of the plugin. * * Since everything within the plugin is registered via hooks, * then kicking off the plugin from this point in the file does * not affect the page life cycle. * * @since 1.0.0 */ function run_foxware_recipe() { $plugin = new foxware_recipe(); $plugin->run(); } run_foxware_recipe(); add_action( 'init', 'create_foxware_recipe' ); function create_foxware_recipe() { register_post_type( 'foxware_recipe', array( 'labels' => array( 'name' => 'Recipes', 'singular_name' => 'Recipe', 'add_new' => 'Add New', 'add_new_item' => 'Add New Recipe', 'edit' => 'Edit', 'edit_item' => 'Edit Recipe', 'new_item' => 'New Recipe', 'view' => 'View', 'view_item' => 'View Recipe', 'search_items' => 'Search Recipes', 'not_found' => 'No Recipes found', 'not_found_in_trash' => 'No Recipes found in Trash', 'parent' => 'Parent Recipe' ), 'public' => true, 'menu_position' => 15, 'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ), 'taxonomies' => array( '' ), 'menu_icon' => plugins_url( 'images/foxware_icon.png', __FILE__ ), 'has_archive' => true ) ); }
Any help would be greatly appreciated, and please let me know if i’m doing this incorrectly, i get the feeling that boilerplate requires me to register a custom post type somewhere else, but im not seeing it in the comments and i dont think boilerplate has documentations set up.
- The topic ‘How do i register multiple custom post types’ is closed to new replies.