james-r2
10/9/2015 - 5:25 AM

Wordpress Custom Post Type

Wordpress Custom Post Type

function init_custom_post_type() {
  $labels = array(
    'name' => _x('Custom Post', 'post type general name', 'adcorp-custom-post'),
    'singular_name' => _x('Custom Post', 'post type singular name', 'adcorp-custom-post'),
    'add_new' => _x('Add Custom Post', 'Custom Post', 'adcorp-custom-post'),
    'add_new_item' => __('Add New Custom Post', 'adcorp-custom-post'),
    'edit_item' => __('Edit Custom Post', 'adcorp-custom-post'),
    'new_item' => __('New Custom Post', 'adcorp-custom-post'),
    'all_items' => __('All Custom Posts', 'adcorp-custom-post'),
    'view_item' => __('View Custom Post', 'adcorp-custom-post'),
    'search_items' => __('Search Custom Posts', 'adcorp-custom-post'),
    'not_found' =>  __('No Custom Posts On found', 'adcorp-custom-post'),
    'not_found_in_trash' => __('No Custom Posts found in Trash', 'adcorp-custom-post'),
    'parent_item_colon' => '',
    'menu_name' => __('Custom Posts', 'adcorp-custom-post')

  );
  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => _x( 'custom-post', 'URL slug', 'adcorp-custom-post' ) ),
    'capability_type' => 'post',
    'has_archive' => true,
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array( 'title', 'editor', 'thumbnail' ),
    'taxonomies' => array('custom_post_category')
  );
  register_post_type('custom-post', $args);
  $labels = array(
    'name'              => _x( 'Custom Post Categories', 'taxonomy general name' ),
    'singular_name'     => _x( 'Custom Post Category', 'taxonomy singular name' ),
    'search_items'      => __( 'Search Custom Post Categories' ),
    'all_items'         => __( 'All Custom Post Categories' ),
    'parent_item'       => __( 'Parent Custom Post Category' ),
    'parent_item_colon' => __( 'Parent Custom Post Category:' ),
    'edit_item'         => __( 'Edit Custom Post Category' ),
    'update_item'       => __( 'Update Custom Post Category' ),
    'add_new_item'      => __( 'Add New Custom Post Category' ),
    'new_item_name'     => __( 'New Custom Post Category' ),
    'menu_name'         => __( 'Custom Post Categories' ),
  );
  $args = array(
    'labels' => $labels,
    'hierarchical' => true,
  );
  register_taxonomy( 'custom_post_category', 'custom-post', $args );
}
add_action( 'init', 'init_custom_post_type' );