From db4e0bddd9f4270ea6f18ea6b553eea2b6204476 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Mon, 14 Dec 2015 08:20:18 -0500 Subject: [PATCH 1/1] new code for custom post type --- index.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 index.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..a6dfec6 --- /dev/null +++ b/index.php @@ -0,0 +1,166 @@ + + * Author URI: + * License: GPLv2 + */ + +// Register Custom Post Type +function michsci_custom_post_type() { + + $labels = array( + 'name' => _x( 'Products', 'Post Type General Name', 'michsci' ), + 'singular_name' => _x( 'Product', 'Post Type Singular Name', 'michsci' ), + 'menu_name' => __( 'Products', 'michsci' ), + 'name_admin_bar' => __( 'Products', 'michsci' ), + 'archives' => __( 'Product Archives', 'michsci' ), + 'parent_item_colon' => __( 'Parent Item:', 'michsci' ), + 'all_items' => __( 'All Items', 'michsci' ), + 'add_new_item' => __( 'Add New Item', 'michsci' ), + 'add_new' => __( 'Add New', 'michsci' ), + 'new_item' => __( 'New Item', 'michsci' ), + 'edit_item' => __( 'Edit Item', 'michsci' ), + 'update_item' => __( 'Update Item', 'michsci' ), + 'view_item' => __( 'View Item', 'michsci' ), + 'search_items' => __( 'Search Item', 'michsci' ), + 'not_found' => __( 'Not found', 'michsci' ), + 'not_found_in_trash' => __( 'Not found in Trash', 'michsci' ), + 'featured_image' => __( 'Featured Image', 'michsci' ), + 'set_featured_image' => __( 'Set featured image', 'michsci' ), + 'remove_featured_image' => __( 'Remove featured image', 'michsci' ), + 'use_featured_image' => __( 'Use as featured image', 'michsci' ), + 'insert_into_item' => __( 'Insert into item', 'michsci' ), + 'uploaded_to_this_item' => __( 'Uploaded to this item', 'michsci' ), + 'items_list' => __( 'Items list', 'michsci' ), + 'items_list_navigation' => __( 'Items list navigation', 'michsci' ), + 'filter_items_list' => __( 'Filter items list', 'michsci' ), + ); + + $rewrite = array( + 'slug' => 'miproduct', + 'with_front' => false, + 'pages' => false, + 'feeds' => false, + ); + + $args = array( + 'label' => __( 'Product', 'michsci' ), + 'description' => __( 'Custom Products', 'michsci' ), + 'labels' => $labels, + 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'page-attributes' ), + 'hierarchical' => true, + 'public' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'menu_position' => 5, + 'menu_icon' => 'dashicons-lightbulb', + 'show_in_admin_bar' => true, + 'show_in_nav_menus' => true, + 'can_export' => true, + 'has_archive' => true, + 'exclude_from_search' => false, + 'publicly_queryable' => true, + 'rewrite' => $rewrite, + 'capability_type' => 'page' + ); + + register_post_type( 'miproduct', $args ); + register_taxonomy_for_object_type( 'michsci_category', 'miproduct' ); + +} + +function michsci_taxonomies() +{ + + $labels = array( + 'name' => _x( 'Category', 'taxonomy general name'), + 'singular_name' => _x( 'Category', 'taxonomy singular name'), + 'search_items' => __( 'Search Categories'), + 'all_items' => __( 'All Categories'), + 'parent_item' => __( 'Parent Category'), + 'parent_item_colon' => __( 'Parent Category'), + 'edit_item' => __( 'Edit Category'), + 'update_item' => __( 'Update Category'), + 'add_new_item' => __( 'Add New Category'), + 'new_item_name' => __( 'New Category Name'), + 'menu_name' => __( 'Product Category'), + ); + + $capabilities = array( + 'manage_terms' => 'manage_categories', + 'edit_terms' => 'manage_categories', + 'delete_terms' => 'manage_categories', + 'assign_terms' => 'edit_posts', + ); + + $args = array( + 'label' => __('Product Category'), + 'rewrite' => array( 'slug' => 'micategory' ), + 'capabilities' => $capabilities, + 'public ' => true, + 'show_in_quick_edit' => true, + 'show_in_admin_column' => true, + 'hierarchical' => true + ); + + register_taxonomy( + 'michsci_category', + 'miproduct', + $args + ); + +} + +function michsci_taxonomy_filter_restrict_manage_posts() +{ + global $typenow; + + $post_types = get_post_types( array( '_builtin' => false ) ); + + if ( in_array( $typenow, $post_types ) ) { + $filters = get_object_taxonomies( $typenow ); + + foreach ( $filters as $tax_slug ) { + $tax_obj = get_taxonomy( $tax_slug ); + wp_dropdown_categories( array( + 'show_option_all' => __( 'Show All ' . $tax_obj->label ), + 'taxonomy' => $tax_slug, + 'name' => $tax_obj->name, + 'orderby' => 'name', + 'selected' => ( isset( $_GET[$tax_slug] ) ), + 'hierarchical' => $tax_obj->hierarchical, + 'show_count' => false, + 'hide_empty' => true + ) ); + } + } +} + +add_action( 'restrict_manage_posts', 'michsci_taxonomy_filter_restrict_manage_posts' ); + +function michsci_taxonomy_filter_post_type_request( $query ) +{ + global $pagenow, $typenow; + + if ( 'edit.php' == $pagenow ) { + $filters = get_object_taxonomies( $typenow ); + foreach ( $filters as $tax_slug ) { + $var = &$query->query_vars[$tax_slug]; + + if ( isset( $var ) ) { + $term = get_term_by( 'id', $var, $tax_slug ); + + $var = $term->slug; + } + } + } +} + +add_filter( 'parse_query', 'michsci_taxonomy_filter_post_type_request' ); + +add_action( 'init', 'michsci_taxonomies' ); +add_action( 'init', 'michsci_custom_post_type' ); -- 2.17.1