not found message for wordpress custom taxonomy - wordpress

i created a custom taxonomy named cancers and a template file for this taxonomy named taxonomy-cancers.php but when i call this url:
http://localhost/cancers even http://localhost/?tax=cancers
wordpress shows page not found and doesn't use my taxonomy template.
this is my code for defining custom taxonomy:
add_action( 'init', 'create_cancers_taxonomy', 0 );
function create_cancers_taxonomy() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'سرطان‌ها', 'taxonomy general name' ),
'singular_name' => _x( 'سرطان', 'taxonomy singular name' ),
'search_items' => __( 'جستجو در میان سرطان‌ها' ),
'all_items' => __( 'تمامی سرطان‌ها' ),
'parent_item' => __( 'دسته اصلی' ),
'parent_item_colon' => __( 'دسته اصلی:' ),
'edit_item' => __( 'ویرایش سرطان' ),
'update_item' => __( 'بروزرسانی سرطان' ),
'add_new_item' => __( 'افزودن سرطان' ),
'new_item_name' => __( 'عنوان سرطان' ),
'menu_name' => __( 'سرطان‌ها' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
);
register_taxonomy( 'cancers', array('cancer', 'post'), $args );
}

I think you forgot to add rewrite parameter in arguments,
Use this arguments:--
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'cancers' ),
);
Note:- After changing this, please update your Permalinks from Settings --> Permalinks once...

Related

register own taxonomy in standard posts

I want to register my own taxonomy in standard, WP posts but it doesn't work. Look at my code
register_taxonomy(
'special-category',
array('post', 'books'),
array(
'hierarchical' => false,
'labels' => array(
//...
),
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array('slug' => 'cpecial-category' )
)
);
Tin my post type books it displays correctly but in standard wp post not. Is it possible to register own taxonomy in standard posts?
Try registering taxonomy in init hook.
Try out this code.
add_action( 'init', 'create_subjects_hierarchical_taxonomy', 0 );
function create_subjects_hierarchical_taxonomy() {
// Add new taxonomy, make it hierarchical like categories
//first do the translations part for GUI
$labels = array(
'name' => _x( 'Subjects', 'taxonomy general name' ),
'singular_name' => _x( 'Subject', 'taxonomy singular name' ),
'search_items' => __( 'Search Subjects' ),
'all_items' => __( 'All Subjects' ),
'parent_item' => __( 'Parent Subject' ),
'parent_item_colon' => __( 'Parent Subject:' ),
'edit_item' => __( 'Edit Subject' ),
'update_item' => __( 'Update Subject' ),
'add_new_item' => __( 'Add New Subject' ),
'new_item_name' => __( 'New Subject Name' ),
'menu_name' => __( 'Subjects' ),
);
// Now register the taxonomy
register_taxonomy(
'special-category',
array('post', 'books'),
array(
'hierarchical' => false,
'labels' => array(
//..
),
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array('slug' => 'cpecial-category' )
)
);
}

Single page for custom post type with custom taxomies desn't work

I created custom post type "testimonials" with custom taxomies
it works well except of sinbgle page, when I click on permalink it shows "not found".
Here is my code for custom post types/taxonomies:
function testimonials_custom_post_type()
{
$labels = array(
'name' => _x('Testimonials', 'Post type general name'),
'singular_name' => _x('Testimonial', 'Post type singular name'),
'add_new' => _x('Add new Testimonial', 'Grower'),
'add_new_item' => __('Add new Testimonial'),
'edit_item' => __('Edit Testimonial'),
'new_item' => __('New Testimonial'),
'all_items' => __('All Testimonials'),
'view_item' => __('View Testimonial'),
'search_items' => __('Search Testimonials'),
'not_found' => __('No testimonials found'),
'not_found_in_trash' => __('No testimonials found in Trash'),
'parent_item_colon' => '',
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => false,
'query_var' => false,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'exclude_from_search' => false,
'supports' => array('title', 'editor', 'thumbnail' ),
'menu_position' => 6,
'menu_icon' => 'dashicons-id',
'taxonomies' => array( 'subjects' ),
);
register_post_type('testimonials', $args);
}
add_action('init', 'testimonials_custom_post_type');
/*register custom taxonomies for testimonials*/
add_action( 'init', 'create_testimonials_taxonomies', 0 );
function create_testimonials_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Subjects', 'subjects', 'textdomain' ),
'singular_name' => _x( 'Subject', 'subject', 'textdomain' ),
'search_items' => __( 'Search Subject', 'textdomain' ),
'all_items' => __( 'All Subjects', 'textdomain' ),
'edit_item' => __( 'Edit Subject', 'textdomain' ),
'update_item' => __( 'Update Subject', 'textdomain' ),
'add_new_item' => __( 'Add new Subject', 'textdomain' ),
'new_item_name' => __( 'New Category Subject', 'textdomain' ),
'menu_name' => __( 'Subject', 'textdomain' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'rewrite' => array( 'slug' => 'subjects' ),
);
register_taxonomy( 'subjects', array( 'testimonials' ), $args );
}
/*register custom taxonomies for testimonials*/
I tried to use flush_rewrite_rules( false ); and tried to update permalinks in wp admin panel it's still not working
For custom post type "testimonials" I created single-testimonials.php in my child theme
Thank you very much for any help!
To fix my bug I had to set 'publicly_queryable' to 'true'
and it works now ))
You could try to create taxonomy-subjects.php and refresh your permalinks after you try each time.

Custom taxonomy archive doesnt work

here is my registerin taxonomy function to my posts.
add_action( 'init', 'marka_taxonomies', 0 );
function marka_taxonomies()
{
$labels = array(
'name' => _x( 'Markalar', 'taxonomy general name' ),
'singular_name' => _x( 'Marka', 'taxonomy singular name' ),
'search_items' => __( 'Markalarda Ara' ),
'all_items' => __( 'Tüm Markalar' ),
'parent_item' => __( 'Alt Marka Kategorisi' ),
'parent_item_colon' => __( 'Üst Marka Kategorisi:' ),
'edit_item' => __( 'Markayı Düzenle' ),
'update_item' => __( 'Markayı Güncelle' ),
'add_new_item' => __( 'Yeni Marka Ekle' ),
'new_item_name' => __( 'Yeni Marka Adı' ),
'menu_name' => __( 'Marka' )
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'marka' )
);
register_taxonomy( 'marka', array( 'post' ), $args );
}
Thnik everthing is normal but the taxonomy-marka.php doesnt work. I still get 404 Not found on title. And there is nothing on my taxonomy archive page. What should i do also where i am wrong ?
When I updated my permalinks option the taxonomy-marka.php page listed my posts.

remove custom taxonomy metabox form custom post type

I have created a custom post type 'hotel' and custom 'taxonomy' so when administrator creates a new hotel and saves it it related custom taxonomy automatically get created but I don't want to show custom metabox in the admin side hotel edit page so for that I used WordPress function but nothing happen.
My custom post code
$Hotel_labels = array(
'name' => _x('Hotels', 'post type general name'),
'singular_name' => _x('Hotel', 'post type singular name'),
'add_new' => _x('Add New', 'Hotel'),
'add_new_item' => __('Add Hotel'),
'edit_item' => __('Edit Hotel'),
'new_item' => __('New Hotel'),
'all_items' => __('All Hotels'),
'view_item' => __('View Hotel'),
'search_items' => __('Search Hotel'),
'not_found' => __('No Hotel found'),
'not_found_in_trash' => __('No Hotel found in Trash'),
'parent_item_colon' => '',
'menu_name' => __('Hotel'),
);
$Hotel_args = array(
'labels' => $Hotel_labels,
'public' => true,
'rewrite' => array('slug' => 'Hotel'),
'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' => 100,
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
'taxonomies' => array('hotel_facilities','package_hotel','post_tag')
);
register_post_type('Hotel',$Hotel_args);
Custom taxonomy code
$Package_labels = array(
'name' => _x( 'Package Hotels', 'taxonomy general name' ),
'singular_name' => _x( 'hotel', 'taxonomy singular name' ),
'search_items' => __( 'Search hotels' ),
'popular_items' => __( 'Popular hotels' ),
'all_items' => __( 'All hotels' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit hotel' ),
'update_item' => __( 'Update hotel' ),
'add_new_item' => __( 'Add New hotel' ),
'new_item_name' => __( 'New hotel Name' ),
'separate_items_with_commas' => __( 'Separate hotels with commas' ),
'add_or_remove_items' => __( 'Add or remove hotels' ),
'choose_from_most_used' => __( 'Choose from the most used hotels' ),
'menu_name' => __( 'Package Hotels' ),
);
register_taxonomy('package_hotel','package',array(
'hierarchical' => false,
'labels' => $Package_labels,
'show_ui' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'show_in_nav_menus' => false,
'rewrite' => array( 'slug' => 'hotels' ),
));
code to remove custom taxonomy metabox form custom post type hotel page
function my_remove_meta_boxes() {
remove_meta_box('tagsdiv_hotels', 'Hotel', 'side');
}
add_action( 'admin_menu', 'my_remove_meta_boxes' );
Since WordPress 3.8 version there is a meta_box_cb argument available. Just change this argument to false in your arguments definition so
$args = array(
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'meta_box_cb' => false,
);
This will leave a sub-menu item under your custom post type but will remove a meta box on post edit page.
change meta box id enter code here
function my_remove_meta_boxes() { remove_meta_box('package_hotel',
'Hotel', 'side'); } add_action( 'admin_menu', 'my_remove_meta_boxes'
);
Change register_taxonomy() : you have kept
'show_ui' => true,
change it to
'show_ui' => false,
this argument determines whether or not a user interface should be displayed to manage the taxonomy. As you don't want it, you have to set it to false.
Ok now the example given in Wordpress.org is like this
`remove_meta_box($custom_taxonomy_slug.'div', $custom_post_type, 'side' );`
// $custom_taxonomy_slug is the slug of your taxonomy, e.g. 'genre' )
// $custom_post_type is the "slug" of your post type, e.g. 'movies' )
which further directs to write syntax for metabox attribute in the function like this
remove_meta_box( 'submitdiv', 'custom_post_id', 'side' );
and in my case the syntax for custom metabox attribute which worked is like this
remove_meta_box('tagsdiv-package_hotel', 'hotel', 'side');
so instead of appending div at the end append tagsdiv_ in the begnning eg:- tagsdiv_$your_custom_taxonomy_id

custom post types wordpress

I am wanting to create a custom post type called testimonials, for this I am wanting to allow the administrator that chance to add a company name/username and what testimonial they have given, I understand I can do this by declaring a custom post-type in my functions.php file, however it does not seem to work and all I get is the normal post fields, can someone tell me where I am going wrong, or how I would do this please?
function testimonials_register() {
$args = array(
'label' => __('Testimonials'),
'singular_label' => __('Testimonial'),
'public' => true,
'show_ui' => true,
'capability_type' => false,
'hierarchical' => false,
'rewirte' => true,
'supports' => array('title', 'editor')
);
register_post_type('testimonial', $args);
}
You spelled rewrite wrong, for starters.
You are missing add_action('init', 'testimonials_regiser'); afer the function.
A more thorough code that's a bit more customized can be as follows:
function testimonials_register() {
$labels = array(
'name' => _x( 'Testimonials', 'post type general name' ),
'singular_name' => _x( 'Testimonial', 'post type singular name' ),
'add_new' => _x( 'Add New', 'testimonial' ),
'add_new_item' => __( 'Add New Testimonial' ),
'edit_item' => __( 'Edit Testimonial' ),
'new_item' => __( 'New Testimonial' ),
'all_items' => __( 'All Testimonials' ),
'view_item' => __( 'View Testimonial' ),
'search_items' => __( 'Search Testimonials' ),
'not_found' => __( 'No testimonials found' ),
'not_found_in_trash' => __( 'No testimonials found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Testimonial'
);
$args = array(
'labels' => $labels,
'description' => '',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor'),
'has_archive' => true,
);
register_post_type( 'testimonial', $args );
}
add_action( 'init', 'testimonials_register' );
Here is a good guide.

Resources