Building relation for two different custom taxonomies - wordpress

Hi I've created a custom post type named as stores. Stores includes two custom taxonomies,
States :
enter image description here
Cities :
enter image description here
Now I want to show states in cities taxonomy so when user adds a city it should fall under some state.
Reason behind to do this I've created a filter page so whenever user selects state in dropdown it should return cities associated with that state in other dropdown so that my queries can work perfectly
Here's how filter are :
enter image description here
Right now it's showing cities from all states
Here's the code for registering Custom Post type :
function create_store_function(){
$labels = array(
'name' => _x('Stores', 'post type general name', 'your_text_domain'),
'singular_name' => _x('Store', 'post type Singular name', 'your_text_domain'),
'add_new' => _x('Add Store', '', 'your_text_domain'),
'add_new_item' => __('Add New Store', 'your_text_domain'),
'edit_item' => __('Edit Store', 'your_text_domain'),
'new_item' => __('New Store', 'your_text_domain'),
'all_items' => __('All Stores', 'your_text_domain'),
'view_item' => __('View Stores', 'your_text_domain'),
'search_items' => __('Search Store', 'your_text_domain'),
'not_found' => __('No Store found', 'your_text_domain'),
'not_found_in_trash' => __('No Store on trash', 'your_text_domain'),
'parent_item_colon' => '',
'menu_name' => __('Stores', 'your_text_domain'),
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'store'),
'capability_type' => 'page',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'taxonomies' => array('State'),
'menu_icon' => 'dashicons-format-gallery',
'supports' => array('title', 'editor', 'excerpt', 'thumbnail')
);
$states = array(
'name' => __('State'),
'singular_name' => __('State'),
'search_items' => __('Search'),
'popular_items' => __('More Used'),
'all_items' => __('All States'),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __('Add new'),
'update_item' => __('Update'),
'add_new_item' => __('Add new State'),
'new_item_name' => __('New'),
'show_admin_column' => true
);
$cities = array(
'name' => __('City'),
'singular_name' => __('City'),
'search_items' => __('Search'),
'popular_items' => __('More Used'),
'all_items' => __('All Cities'),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __('Add new'),
'update_item' => __('Update'),
'add_new_item' => __('Add new City'),
'new_item_name' => __('New'),
'show_admin_column' => true
);
register_taxonomy('store_state', array('store'), array(
'labels' => $states,
'singular_label' => 'store_state',
'all_items' => 'State',
'rewrite' => array('slug' => 'state'),
'hierarchical' => True,
'public' => true,
'publicly_queryable' => true,
'show_in_quick_edit' => true,
'show_admin_column' => true,
)
);
register_taxonomy('store_cities', array('store'), array(
'labels' => $cities,
'singular_label' => 'store_cities',
'all_items' => 'Cities',
'rewrite' => array('slug' => 'city'),
'hierarchical' => True,
'public' => true,
'publicly_queryable' => true,
'show_in_quick_edit' => true,
'show_admin_column' => true,)
);
register_post_type('store', $args);
flush_rewrite_rules();
}
add_action('init', 'create_store_function');
And searchbar code :
<form action="" method="get" autocomplete="off" id="search-filter">
State
'store_state', 'orderby' => 'name' ) ) ) :
echo 'Select category...';
foreach ( $states as $state ) :
$count = $state->count;
echo 'name . '">' . $state->name . " ($count) " . '';
endforeach;
echo '';
endif;
?>
City
'store_cities', 'orderby' => 'name' ) ) ) :
echo 'Select category...';
foreach ( $cities as $city ) :
$count2 = $city->count;
echo 'name . '">' . $city->name . " ($count2) " . '';
endforeach;
echo '';
endif;
?>
Am I missing something or can it be achieved without creating any relationship between taxonomies and using logics in code?

Related

WordPress - Custom taxonomies not showing in Appearance > Menu

I have a custom post type called Resources:
register_post_type(
'resources',
build_post_args(
'resources', 'Resource', 'Resources',
array(
'menu_icon' => 'dashicons-welcome-write-blog',
'menu_position' => 20,
'has_archive' => true,
'public' => true,
'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
'taxonomies' => array('sector', 'subject', 'type'),
)
)
);
I have also created the taxonomy of type which is assigned to Resources:
register_taxonomy(
'type',
'type',
array(
'hierarchical' => true,
'label' => 'Type',
'query_var' => true,
'rewrite' => array(
'slug' => 'type',
'with_front' => false
)
)
);
In the WordPress backend, here are all my type's:
However, when I go to Appearance > Menus > and click on the Categories dropdown, only these options show:
Why is this?
Hello Please add below code and check as you are missing lots of things when creating resources post type. (Note: Please remove all your code added for creating resources post and type taxonomy)
function ro_resources_custom_post_type() {
$labels = array(
'name' => __( 'Resources' ),
'singular_name' => __( 'Resource'),
'menu_name' => __( 'Resources'),
'parent_item_colon' => __( 'Parent Resource'),
'all_items' => __( 'All Resources'),
'view_item' => __( 'View Resource'),
'add_new_item' => __( 'Add New Resource'),
'add_new' => __( 'Add New'),
'edit_item' => __( 'Edit Resource'),
'update_item' => __( 'Update Resource'),
'search_items' => __( 'Search Resource'),
'not_found' => __( 'Not Found'),
'not_found_in_trash' => __( 'Not found in Trash')
);
$args = array(
'label' => __( 'resources'),
'description' => __( 'Best Resources'),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => true,
'can_export' => true,
'exclude_from_search' => false,
'yarpp_support' => true,
'publicly_queryable' => true,
'capability_type' => 'page'
);
register_post_type( 'resources', $args );
}
add_action( 'init', 'ro_resources_custom_post_type', 0 );
add_action( 'init', 'ro_create_resources_custom_taxonomy', 0 );
//create a custom taxonomy name it "type" for your posts
function ro_create_resources_custom_taxonomy() {
$labels = array(
'name' => _x( 'Types', 'taxonomy general name' ),
'singular_name' => _x( 'Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Types' ),
'all_items' => __( 'All Types' ),
'parent_item' => __( 'Parent Type' ),
'parent_item_colon' => __( 'Parent Type:' ),
'edit_item' => __( 'Edit Type' ),
'update_item' => __( 'Update Type' ),
'add_new_item' => __( 'Add New Type' ),
'new_item_name' => __( 'New Type Name' ),
'menu_name' => __( 'Types' ),
);
register_taxonomy('types',array('resources'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'type' ),
));
}
Tested and works well

Custom taxonomy for product not working

I have created a custom taxonomy for WooCommerce products.
function add_hunts_type(){
// Car Hunts
$cHunt_labels = array(
'name' => __( 'Hunts', 'pixar' ),
'singular_name' => __( 'Hunt', 'pixar' ),
'search_items' => __( 'Search Hunts', 'pixar' ),
'all_items' => __( 'All Hunts', 'pixar' ),
'parent_item' => __( 'Parent Hunt', 'pixar' ),
'parent_item_colon' => __( 'Parent Hunt:', 'pixar' ),
'edit_item' => __( 'Edit Hunt', 'pixar' ),
'update_item' => __( 'Update Hunt', 'pixar' ),
'add_new_item' => __( 'Add New Hunt', 'pixar' ),
'new_item_name' => __( 'New Hunt', 'pixar' ),
'menu_name' => __( 'Hunts', 'pixar' ),
);
$cHunt_args = array(
'labels' => $cHunt_labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'carhunt' )
);
register_taxonomy( 'car_Hunt', 'product', $cHunt_args );
}
add_action( 'init', 'add_hunts_type', 0 );
/* Flush rewrite rules for custom post types. */
add_action( 'after_switch_theme', 'flush_rewrite_rules' );
This is working when I login into admin. When I want to try from the front end it's not working.
I have change permalinks
I have deleted .htaccess and regenerated it
I have other inbuilt things which are working properly
Please let me know if I've missed something.
Register Custom Taxonomy in WooCommerce
add below function in function.php
<?php
// Register Custom Taxonomy
function custom_taxonomy_Hunt() {
$labels = array(
'name' => 'Hunts',
'singular_name' => 'Hunt',
'menu_name' => 'Hunt',
'all_items' => 'All Hunts',
'parent_item' => 'Parent Hunt',
'parent_item_colon' => 'Parent Hunt:',
'new_item_name' => 'New Hunt Name',
'add_new_item' => 'Add New Hunt',
'edit_item' => 'Edit Hunt',
'update_item' => 'Update Hunt',
'separate_items_with_commas' => 'Separate Hunt with commas',
'search_items' => 'Search Hunts',
'add_or_remove_items' => 'Add or remove Hunts',
'choose_from_most_used' => 'Choose from the most used Hunts',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'carhunt' )
);
register_taxonomy( 'carhunt', 'product', $args );
register_taxonomy_for_object_type( 'carhunt', 'product' );
}
add_action( 'init', 'custom_taxonomy_Hunt' );
?>

Taxonomy term permalink is not working as expected

I have CPT called forms_cpt and a Taxonomy called forms_tax. In my page-forms.php I am able to crate a list of forms_tax terms like
<ul>
<?php
foreach ($tax_terms as $tax_term) {
echo '<li>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a></li>';
}
?>
</ul>
which is creating a list of terms. but whenever I click on them it landed in a wrong URL. For example if click on soccer term it landed at
http://www.domain.ca/soccer/
instead of
http://www.domain.ca/Forms/soccer/
What am I doing wrong?
function gen_forms_tax() {
$labels = array(
'name' => 'Form Types',
'singular_name' => 'Form Type',
'menu_name' => 'Form Types',
'all_items' => 'All Form Types',
'parent_item' => 'Form Parent',
'parent_item_colon' => 'Form Parents:',
'new_item_name' => 'New Form Name',
'add_new_item' => 'Add New Form',
'edit_item' => 'Edit Form',
'update_item' => 'Update Form',
'separate_items_with_commas' => 'Separate Form with commas',
'search_items' => 'Search Form',
'add_or_remove_items' => 'Add or remove Form',
'choose_from_most_used' => 'Choose from the most used Form',
'not_found' => 'Form Not Found',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'forms_tax', array( 'forms_cpt' ), $args );
}
add_action( 'init', 'gen_forms_tax', 0 );
function gen_forms_cpt() {
$labels = array(
'name' => 'Forms',
'singular_name' => 'Form',
'menu_name' => 'Form',
'name_admin_bar' => 'Form',
'parent_item_colon' => 'Form Parent:',
'all_items' => 'All Forms',
'view_item' => 'View Forms',
'add_new_item' => 'Add New Form',
'add_new' => 'Add New Form',
'new_item' => 'New Form',
'edit_item' => 'Edit Form',
'update_item' => 'Update Form',
'search_items' => 'Search Form',
'not_found' => 'Form Not found',
'not_found_in_trash' => 'Form Not found in Trash',
);
$args = array(
'description' => 'This Post Type Adds Form to Website',
'labels' => $labels,
'supports' => array( 'title', 'excerpt', ),
'taxonomies' => array( 'forms_tax' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'rewrite' => array( 'slug' => 'Forms','with_front' => true, 'hierarchical' => true ),
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'forms_cpt', $args );
}
add_action( 'init', 'gen_forms_cpt', 0 );
Solution : You need to follow the steps given below.
1) Go to Settings from Admin panel.
2) Go to permalinks
3) Save the permalinks
It should work after you save the parmalinks. You always need update the permalinks once you add any rewrite rule to the site.

get_terms on custom post type/taxonomy returns nothing

I created a custom post type and custom taxonomy...
function create_deals_post_type() {
register_post_type('Deals',
array(
'labels' => array (
'name' => __('Deals'),
'singular_name' => __('Deal'),
'add_new' => __('Add New'),
'add_new_item' => __('Add a new Deal'),
'view_item' => __('View Deal'),
'edit_item' => __('Edit Deal'),
'new_item' => __('New Deal'),
'all_items' => __('All Deals'),
'search_items' => __('Search Deals'),
'not_found' => __('No deals found'),
'not_found_in_trash' => __('No deals found in the trash'),
'parent_item_colon' => '',
'menu_name' => 'Deals'
),
'can_export' => true,
'description' => 'Delicious Deals',
'public' => true,
'has_archive' => true,
'rewrite' => apply_filters('et_project_posttype_rewrite_args', array(
'feeds' => true,
'slug' => 'deals',
'with_front' => false,)),
'capability_type' => 'post',
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 0,
'supports' => array('title', 'editor', 'thumbnail')
)
);
$labels = array(
'name' => _x('Categories', 'Deal category name', 'Divi'),
'singular_name' => _x('Category', 'Deal category singular name', 'Divi'),
'search_items' => __('Search Categories', 'Divi'),
'all_items' => __('All Categories', 'Divi'),
'parent_item' => __('Parent Category', 'Divi'),
'parent_item_colon' => __('Parent Category:', 'Divi'),
'edit_item' => __('Edit Category', 'Divi'),
'update_item' => __('Update Category', 'Divi'),
'add_new_item' => __('Add New Category', 'Divi'),
'new_item_name' => __('New Category Name', 'Divi'),
'menu_name' => __('Categories', 'Divi'),
);
register_taxonomy('deals-category', 'deals', array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,)
);
$labels = array(
'name' => _x('Tags', 'Deal Tag name', 'Divi'),
'singular_name' => _x('Tag', 'Deal tag singular name', 'Divi'),
'search_items' => __('Search Tags', 'Divi'),
'all_items' => __('All Tags', 'Divi'),
'parent_item' => __('Parent Tag', 'Divi'),
'parent_item_colon' => __('Parent Tag:', 'Divi'),
'edit_item' => __('Edit Tag', 'Divi'),
'update_item' => __('Update Tag', 'Divi'),
'add_new_item' => __('Add New Tag', 'Divi'),
'new_item_name' => __('New Tag Name', 'Divi'),
'menu_name' => __('Tags', 'Divi'),
);
register_taxonomy('deals_tag', 'deals', array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,)
);
}
add_action('init', 'create_deals_post_type');
Afterwards I created multiple multiple categories and tags. I'd like to retrieve the categories but when running the following, it doesn't return anything...
$category_array = get_terms('deals-category');
foreach ($category_array as $item) {
echo 'Item: ' . $item->name . '. Slug: ' . $item->slug . '</br>';
}
Any assistance would be greatly appreciated.
I was tried with your code & working fine. [ experiment's screenshot: http://imgur.com/a/jPms7 ]
Please make sure that you have created at-least one post under post-type 'deals' & assign some deals category with it.
[ or you can create the post type & taxonomies newly in standard way from here: https://generatewp.com/post-type/ ]

How to create custom post types in WordPress?

I want to know the procedure of how to create custom post types with WordPress. I will be thankful if anyone help me with complete procedure of code and plugins. I will also be writing a blog post regarding this issue and I need help from top contributors of Stackoverflow.
Add code similar to this to your functions.php
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'your_custom_name',
array(
'labels' => array(
'name' => __( 'Custom_names' ),
'singular_name' => __( 'Custom_names' )
),
'public' => true,
'has_archive' => true,
)
);
}
after it you can see a another option in your dashbooard left bar to add custom post.
see more about Post Types
<?php
require_once 'wp-load.php'; //path of wp-load.php
$name = 'my post';
$content = 'dummy Content here';
$featured_image = 'fullimage url.jpg'; //pass here full image url
$post_data = array(
'post_title' => wp_strip_all_tags( $name ),
'post_content' => $content,
'post_status' => 'publish',
'post_type' => 'post',
'post_author' => 1,
'post_category' => array(1,2),
'page_template' => ''
);
$post_id = wp_insert_post( $post_data, $error_obj );
// for custom field
//add_post_meta( $post_id, 'post_date', 'Dec 5, 2018' ); // second parameter is your custom field name, 3rd parameter is value
generate_Featured_Image($featured_image, $post_id );
function generate_Featured_Image( $image_url, $post_id ){
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if(wp_mkdir_p($upload_dir['path']))
$file = $upload_dir['path'] . '/' . $filename;
else
$file = $upload_dir['basedir'] . '/' . $filename;
file_put_contents($file, $image_data);
$wp_filetype = wp_check_filetype($filename, null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => sanitize_file_name($filename),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $file, $post_id );
require_once(ABSPATH . 'wp-admin/includes/image.php');
$attach_data = wp_generate_attachment_metadata( $attach_id, $file );
$res1= wp_update_attachment_metadata( $attach_id, $attach_data );
$res2= set_post_thumbnail( $post_id, $attach_id );
echo 'post created...';
}
?>
function my_custom_event() {
$labels = array(
'name' => _x( 'Events', 'post type general name' ),
'singular_name' => _x( 'Events', 'post type singular name' ),
'add_new' => _x( 'Add New', 'Events' ),
'add_new_item' => __( 'Add New Events' ),
'edit_item' => __( 'Edit Events' ),
'new_item' => __( 'New Events' ),
'all_items' => __( 'All Events' ),
'view_item' => __( 'View Events' ),
'search_items' => __( 'Search Events' ),
'not_found' => __( 'No Events found' ),
'not_found_in_trash' => __( 'No Events found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Events'
);
$args = array(
'labels' => $labels,
'description' => 'Events',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'menu_position' => 5,
'supports' => array( 'title' , 'thumbnail', 'editor', 'page-attributes'),
'has_archive' => true,
);
register_post_type( 'event', $args );
}
add_action( 'init', 'my_custom_event' );
## This is my full working code for creating custom post types ##
function slide_init()
{
$labels = array(
'name' => 'Slider',
'singular_name' => 'Slider',
'menu_name' => 'Slider',
'name_admin_bar' => 'Slider',
'add_new' => 'Add New Slider',
'add_new_item' => 'Add New Slider',
'new_item' => 'New Slider',
'edit_item' => 'Edit Slider',
'view_item' => 'View Slider',
'all_items' => 'All Slider Images',
'search items' => 'Search Slider',
'parent_item_colon' => 'Parent Slider',
'not_found' => 'No Slider Found',
'not_found_in_trash' => 'No Slider Found In Trash',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicaly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'Slider' ),
'capability_type' => 'post',
'has_archive' => true,
'Hierarchical' => false,
'menu_position' => null,
'menu_icon' => 'dashicons-format-image',
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments','hierarchical','trackbacks','custom-fields','revisions','page-attributes'),
'taxonomies' =>array('category'),
);
register_post_type('Slider',$args);
register_taxonomy('Slider_category','Slider',array('hierarchical' => true, 'label' => 'Category', 'query_var' => true, 'rewrite' => array('slug' => 'slider-category')));
}
add_action('init','slide_init');
/** Meet the team custom post
You can use below WordPress script to create custom post type without any plugins */
$labels = array(
'name' => _x('Team', 'Team', 'Team') ,
'singular_name' => _x('Team', 'Team', 'rjis') ,
'menu_name' => _x('Meet the Team', 'admin menu', 'rjis') ,
'name_admin_bar' => _x('Team', 'add new on admin bar', 'rjis') ,
'add_new' => _x('Add New', 'Team', 'rjis') ,
'add_new_item' => __('Add New Team', 'rjis') ,
'new_item' => __('New Team', 'rjis') ,
'edit_item' => __('Edit Team', 'rjis') ,
'view_item' => __('View Team', 'rjis') ,
'all_items' => __('All Team Members', 'rjis') ,
'search_items' => __('Search Team', 'rjis') ,
'parent_item_colon' => __('Parent Team:', 'rjis') ,
'not_found' => __('No Team found.', 'rjis') ,
'not_found_in_trash' => __('No Team found in Trash.', 'rjis')
);
$args = array(
'labels' => $labels,
'description' => __('Description.', 'Meet the team') ,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'team'
) ,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'menu_position' => null,
'supports' => array(
'title',
'editor',
'author',
'thumbnail',
'excerpt'
) ,
'menu_icon' => PLUGIN_URL . "images/team.png"
);
register_post_type('team', $args);
Here Career word is Used for Given name for the PostType. You can make multiple post type just change Carrer Name.
// career CUSTOM POST
$labels = array(
'name' => 'career',
'singular_name' => 'career',
'add_new' => 'Add career',
'add_new_item' => 'Add New career',
'edit_item' => 'Edit career',
'new_item' => 'New career',
'all_items' => 'All career',
'view_item' => 'View career',
'search_items' => 'Search career',
'not_found' => 'No career found',
'not_found_in_trash' => 'No career found in Trash',
'parent_item_colon' => '',
'menu_name' => 'career'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'taxonomies' => array('career_cat'),
'supports' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'custom-fields'
)
);
register_post_type('career', $args);
$labels = array(
'name' => 'career_Category',
'singular_name' => 'career',
'search_items' => 'Search career_Categories',
'all_items' => 'All career_Categories',
'parent_item' => 'Parent career_Category',
'parent_item_colon' => 'Parent career_Category:',
'edit_item' => 'Edit career_Category',
'update_item' => 'Update career_Category',
'add_new_item' => 'Add New career_Category',
'new_item_name' => 'New Category Name',
'menu_name' => 'career_Categories'
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'rewrite' => false,
'capabilities' => array('manage_terms')
);
register_taxonomy('career_cat', array('career'), $args);
add_theme_support('post-thumbnails', array('career'));
set_post_thumbnail_size(100, 100);
"Portfolio" name Used for the PostType. You can Add portfolio-category remove and also add tags.
function ag_custom_post_type_init() {
$ag_cust_post_argu = '';
$ag_cust_post_argu = array(
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'has_archive' => true,
'hierarchical' => true,
'menu_position' => null,
'menu_icon' => null,
'supports' => array( 'title', 'editor' )
);
register_post_type(
'portfolio', array(
'labels' => array('name' => __( 'Portfolio' ), 'singular_name' => __( 'portfolio' ) ),
'hierarchical' => true,
'public' => true,
'rewrite' => array(
'slug' => 'portfolio',
'with_front' => false,
),
'menu_icon' => 'dashicons-admin-site',
'has_archive' => true,
'parent' => 'Portfolio',
'supports' => array('page-attributes','title', 'editor', 'thumbnail', 'comments', 'excerpt'),
$ag_cust_post_argu,
)
);
}
add_action( 'init', 'ag_custom_post_type_init' );
function custom_post_type_tax_init_portfolio() {
register_taxonomy(
'portfolio-category',
'portfolio',
array(
'label' => __( 'Categories' ),
'hierarchical' => true,
'rewrite' => array(
'slug' => 'portfolio-category',
'with_front' => false,
),
)
);
}
add_action( 'init', 'custom_post_type_tax_init_portfolio' );
function custom_post_type_tag_init_portfolio() {
register_taxonomy('portfolio_tag', 'portfolio', array(
'hierarchical' => false,
'label' => "Tags",
'singular_name' => "tag",
'rewrite' => array(
'slug' => 'portfolio-tag',
'with_front' => false,
),
'query_var' => true
)
);
}
add_action( 'init', 'custom_post_type_tag_init_portfolio' );

Resources