Created
September 27, 2016 10:30
-
-
Save raekul/bf2c47492d84c62dd1115cded70fe2e4 to your computer and use it in GitHub Desktop.
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 - Hardware | |
function adaptive_hardware_post_type() { | |
$labels = array( | |
'name' => _x( 'Hardware', 'Post Type General Name', 'hardware_post_type' ), | |
'singular_name' => _x( 'Hardware', 'Post Type Singular Name', 'hardware_post_type' ), | |
'menu_name' => __( 'Hardware', 'hardware_post_type' ), | |
'name_admin_bar' => __( 'Hardware', 'hardware_post_type' ), | |
'archives' => __( 'Hardware Archives', 'hardware_post_type' ), | |
'parent_item_colon' => __( 'Parent Hardware:', 'hardware_post_type' ), | |
'all_items' => __( 'All Hardware', 'hardware_post_type' ), | |
'add_new_item' => __( 'Add New Hardware', 'hardware_post_type' ), | |
'add_new' => __( 'Add New Hardware', 'hardware_post_type' ), | |
'new_item' => __( 'New Hardware', 'hardware_post_type' ), | |
'edit_item' => __( 'Edit Hardware', 'hardware_post_type' ), | |
'update_item' => __( 'Update Hardware', 'hardware_post_type' ), | |
'view_item' => __( 'View Hardware', 'hardware_post_type' ), | |
'search_items' => __( 'Search Hardware', 'hardware_post_type' ), | |
'not_found' => __( 'Not found', 'hardware_post_type' ), | |
'not_found_in_trash' => __( 'Not found in Trash', 'hardware_post_type' ), | |
'featured_image' => __( 'Featured Hardware Image', 'hardware_post_type' ), | |
'set_featured_image' => __( 'Set featured hardware image', 'hardware_post_type' ), | |
'remove_featured_image' => __( 'Remove featured hardware image', 'hardware_post_type' ), | |
'use_featured_image' => __( 'Use as featured hardware image', 'hardware_post_type' ), | |
'insert_into_item' => __( 'Insert into Hardware', 'hardware_post_type' ), | |
'uploaded_to_this_item' => __( 'Uploaded to this Hardware', 'hardware_post_type' ), | |
'items_list' => __( 'Hardware list', 'hardware_post_type' ), | |
'items_list_navigation' => __( 'Hardware list navigation', 'hardware_post_type' ), | |
'filter_items_list' => __( 'Filter Hardware list', 'hardware_post_type' ), | |
); | |
$args = array( | |
'label' => __( 'Hardware', 'hardware_post_type' ), | |
'description' => __( 'Hardware Description', 'hardware_post_type' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'page-attributes', ), | |
'taxonomies' => array(''), | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'menu_icon' => 'dashicons-admin-settings', | |
'show_in_admin_bar' => true, | |
'show_in_nav_menus' => true, | |
'can_export' => true, | |
'has_archive' => 'hardware', | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'page', | |
'rewrite' => array( | |
'slug' => 'hardware/%hardware_type%', | |
'with_front' => true | |
) | |
); | |
register_post_type( 'hardware', $args ); | |
} | |
add_action( 'init', 'adaptive_hardware_post_type', 0 ); | |
include('hardware-taxonomies/adaptive_taxonomy_hardwaretype.php'); | |
function add_hardware_permastructure() | |
{ | |
global $wp_rewrite; | |
add_permastruct('hardware_type', 'hardware/%hardware_type%', false); | |
} | |
add_action('wp_loaded', 'add_hardware_permastructure'); | |
function hardware_permalink_structure($url, $post) | |
{ | |
if ($post->post_type !== 'hardware') return $url; | |
$terms = get_the_terms($post->ID, 'hardware_type'); | |
if (!$terms) return str_replace('%hardware_type%/', '', $url); | |
return str_replace('%hardware_type%', array_pop($terms)->slug, $url ); | |
} | |
add_filter( 'post_type_link', 'hardware_permalink_structure', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment