Created
January 11, 2017 04:50
-
-
Save amitkolloldey/8949ac43d4eab2f1abc4b744c35a394d to your computer and use it in GitHub Desktop.
Register custompost type and taxonomy from plugin
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 | |
/* | |
Plugin Name:Bali Homes Toolbox | |
Description:This plugin is for Bali Homes theme. | |
Author: Logic Fighters | |
Version: 1.0 | |
*/ | |
if ( ! class_exists( 'bh_custom_post_types' ) ): | |
function bh_custom_post_types() { | |
register_post_type( 'villa', | |
array( | |
'labels' => array( | |
'name' => 'Villas' , | |
'singular_name' => 'Villa', | |
'add_new' => 'Add new Villa', | |
'add_new_item' => 'Add new Villa', | |
), | |
'public' => true, | |
'menu_icon'=>'dashicons-images-alt2', | |
'supports' => array( 'title','editor','thumbnail','excerpt','custom-fields'), | |
) | |
); | |
} | |
add_action( 'init', 'bh_custom_post_types' ); | |
endif; | |
if(!function_exists('bh_register_location_taxonomy')): | |
function bh_register_location_taxonomy(){ | |
register_taxonomy( | |
'villa_loc', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). | |
'villa', //post type name | |
array( | |
'hierarchical' => true, | |
'label' => 'Villa Location', //Display name | |
'labels' => array( | |
'singular_name' => 'Villa Location', | |
'all_items' => 'All Locations', | |
'edit_item' => 'Edit Location', | |
'view_item' => 'View Location', | |
'update_item' => 'Update Location', | |
'add_new_item' => 'Add New Location', | |
'new_item_name' => 'New Location Name', | |
), | |
'query_var' => true, | |
'show_admin_column' => true, | |
'rewrite'=> array( | |
'slug' => 'villa-location', // This controls the base slug that will display before each term | |
'with_front' => true // Don't display the category base before | |
) | |
) | |
); | |
} | |
add_action( 'init', 'bh_register_location_taxonomy'); | |
endif; | |
add_action( 'init', 'bh_register_taxonomy_for_object_type' ); | |
function bh_register_taxonomy_for_object_type() { | |
register_taxonomy_for_object_type( 'post_tag', 'villa' ); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment