wordpress custom post type and taxonomy


Put these code at function.php file


add_action('init', 'register_post_types_and_taxonomie', 0);

 function register_post_types_and_taxonomie() {
//  New post type 
    $labels = array(
        'name' => _x('Place', 'post type general name'),
        'singular_name' => _x('Place', 'post type general name'),
        'singular_name' => _x('All Place', 'Place type singular name'),
        'add_new' => _x('Add New', 'Place'),
        'add_new_item' => __('Add New Place'),
        'edit_item' => __('Edit Place'),
        'new_item' => __('New Place'),
        'view_item' => __('View Place'),
        'search_items' => __('Search Place'),
        'not_found' => __('Nothing found'),
        'not_found_in_trash' => __('Nothing found in Trash'),
        'parent_item_colon' => ''
    );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'query_var' => true,
        'menu_icon' => get_stylesheet_directory_uri() . '/sun-small.png',
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title', 'editor', 'thumbnail')
    );

    register_post_type('place_register', $args);

//  Custom Taxonomy for Place
    $labels = array(
        'name' => _x('Place cat', 'taxonomy general name'),
        'singular_name' => _x('Place Category', 'taxonomy singular name'),
        'search_items' => __('Search Place Categories'),
        'all_items' => __('All Place Categories'),
        'parent_item' => __('Parent Place Category'),
        'parent_item_colon' => __('Parent Place Category:'),
        'edit_item' => __('Edit Place Category'),
        'update_item' => __('Update Place Category'),
        'add_new_item' => __('Add New Place Category'),
        'new_item_name' => __('New Place Category'),
        'menu_name' => __('Place Categories'),
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
    );

    register_taxonomy('category_in_place', 'place_register', $args);

    flush_rewrite_rules();
}



Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s