Use a WooCommerce product attribute taxonomy for a custom post type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Register Custom Post Type | |
// Note: Using woocommerce_after_register_taxonomy hook instead of init because we're using a product attribute taxonomy with this CPT | |
function doublee_cpt_case_study() { | |
$labels = array( | |
'name' => _x('Case studies', 'Post Type General Name', 'doubleedesign'), | |
'singular_name' => _x('Case study', 'Post Type Singular Name', 'doubleedesign'), | |
'menu_name' => __('Case studies', 'doubleedesign'), | |
'name_admin_bar' => __('Case study', 'doubleedesign'), | |
'archives' => __('Case Study Archives', 'doubleedesign'), | |
'attributes' => __('Case study Attributes', 'doubleedesign'), | |
'parent_item_colon' => __('Parent case study:', 'doubleedesign'), | |
'all_items' => __('All case studies', 'doubleedesign'), | |
'add_new_item' => __('Add New case study', 'doubleedesign'), | |
'add_new' => __('Add New', 'doubleedesign'), | |
'new_item' => __('New case study', 'doubleedesign'), | |
'edit_item' => __('Edit case study', 'doubleedesign'), | |
'update_item' => __('Update case study', 'doubleedesign'), | |
'view_item' => __('View case study', 'doubleedesign'), | |
'view_items' => __('View case studies', 'doubleedesign'), | |
'search_items' => __('Search case studies', 'doubleedesign'), | |
'not_found' => __('Not found', 'doubleedesign'), | |
'not_found_in_trash' => __('Not found in Trash', 'doubleedesign'), | |
'featured_image' => __('Featured Image', 'doubleedesign'), | |
'set_featured_image' => __('Set featured image', 'doubleedesign'), | |
'remove_featured_image' => __('Remove featured image', 'doubleedesign'), | |
'use_featured_image' => __('Use as featured image', 'doubleedesign'), | |
'insert_into_item' => __('Insert into case study', 'doubleedesign'), | |
'uploaded_to_this_item' => __('Uploaded to this case study', 'doubleedesign'), | |
'items_list' => __('Items list', 'doubleedesign'), | |
'items_list_navigation' => __('Items list navigation', 'doubleedesign'), | |
'filter_items_list' => __('Filter items list', 'doubleedesign'), | |
); | |
$rewrite = array( | |
'slug' => 'case-study', | |
'with_front' => true, | |
'pages' => true, | |
'feeds' => true, | |
); | |
$args = array( | |
'label' => __('Case study', 'doubleedesign'), | |
'description' => __('Case studies', 'doubleedesign'), | |
'labels' => $labels, | |
'supports' => array('title', 'editor', 'thumbnail', 'revisions'), | |
'taxonomies' => array('case_study_category', 'pa_industry'), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'menu_icon' => 'dashicons-format-aside', | |
'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' => 'post', | |
); | |
register_post_type('case_study', $args); | |
} | |
add_action('woocommerce_after_register_taxonomy', 'doublee_cpt_case_study', 0); | |
// Enable post edit metabox for pa_industry taxonomy | |
function doublee_case_study_pa_industry($args, $taxonomy) { | |
if ('pa_industry' === $taxonomy) { | |
$args['meta_box_cb'] = 'post_categories_meta_box'; | |
} | |
return $args; | |
} | |
add_filter('register_taxonomy_args', 'doublee_case_study_pa_industry', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment