0

I have a taxonomy register with name doctor-services and I have a taxonomy template with name taxonomy-doctor-services.php but when I click on taxonomy link it does not display detail of the taxonomy. Here is a code

  function doctors_custom_post(){
    $labels = array(
        'name' => 'Doctors',
        'singular_name' => 'Doctor',
        'add_new' => 'Add Doctor',
        'add_new_item' => 'Add New Doctor',
        'all_items' => 'All Doctors',
        'edit_item' => 'Edit Item',
        'new_item' => 'New Item',
        'view_item' => 'View Item',
        'search_items' => 'Search Doctors',
        'not_found' => 'No record found',
        'not_found_in_trash' => 'No items found in trash',
        'parent_item_colon' => 'Parent Item'
        );
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'hierarchical' => false,
            'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'revisions'),
            //'taxonomies' => array('category', 'post_tags'),
            'menu_position' => 15,
            'exclude_from_search' => false
            );
            register_post_type('my-doctor', $args);     
}
add_action('init', 'doctors_custom_post');
add_action( 'init', 'doctors_my_taxonomy');
function doctors_my_taxonomy(){
// custom post type taxonomies
        $labels = array(
        'name' => 'Doctor Departments',
        'singular_name' => 'Doctor Department',
        'add_new' => 'Add Department',
        'add_new_item' => 'Add New Department',
        'all_items' => 'All Departments',
        'edit_item' => 'Edit Item',
        'new_item' => 'New Item',
        'view_item' => 'View Item',
        'update_item' => 'Update Department',
        'search_items' => 'Search Departments',
        'not_found' => 'No record found',
        'not_found_in_trash' => 'No items found in trash',
        'parent_item_colon' => 'Parent Item',
        'menu_name' => 'Departments'
        );
        $args = array(
            'labels' => $labels,
            'hierarchical' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'doctor_departments'),
            'show_ui' => true,
            'show_admin_column' => true,
            'query_var' => true,
            );
            register_taxonomy('doctor-department', array('my-doctor'), $args);
    $labels = array(
        'name' => 'Diseases',
        'singular_name' => 'Diseases',
        'add_new' => 'Add Disease',
        'add_new_item' => 'Add New Disease',
        'all_items' => 'All Disease',
        'edit_item' => 'Edit Item',
        'new_item' => 'New Item',
        'view_item' => 'View Item',
        'update_item' => 'Update Disease',
        'search_items' => 'Search Disease',
        'not_found' => 'No record found',
        'not_found_in_trash' => 'No items found in trash',
        'parent_item_colon' => 'Parent Item',
        'menu_name' => 'Diseases'
        );
        $args = array(
            'labels' => $labels,
            'hierarchical' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'doctor_diseases'),
            'show_ui' => true,
            'show_admin_column' => true,
            'query_var' => true,
            );
            register_taxonomy('doctor-diseases', array('my-doctor'), $args);
    $labels = array(
        'name' => 'Services',
        'singular_name' => 'Service',
        'add_new' => 'Add Service',
        'add_new_item' => 'Add New Service',
        'all_items' => 'All Services',
        'edit_item' => 'Edit Item',
        'new_item' => 'New Item',
        'view_item' => 'View Item',
        'update_item' => 'Update Service',
        'search_items' => 'Search Service',
        'not_found' => 'No record found',
        'not_found_in_trash' => 'No items found in trash',
        'parent_item_colon' => 'Parent Item',
        'menu_name' => 'Services'
        );
        $args = array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'hierarchical' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'doctor_services'),
            'show_ui' => true,
            'show_admin_column' => true,
            'query_var' => true,
            );
            register_taxonomy('doctor-services', array('my-doctor'), $args);
}

and taxonomy Services page

      <?php
      get_header(); ?>
      <div id="primary">
      <div id="content" class="content">
      <div class="container">
      <div class="row">
    <div class="col-sm-12 col-md-9 col-lg-9">
       <h2> <?php 
        single_cat_title();
        ?>
        </h2>
        <?php category_description(); ?>
       </div>
        </div>
        </div>
          </div>
          </div>
        <?php get_footer(); ?>

and taxonomy link when I clicked

http://example.com/doctor_services/xray/

Please help where is the error

31
  • Goto > settings >permalinks->select (post name) > save changes this will refresh your permalinks structure.
    – DHL17
    Commented Nov 14, 2017 at 11:12
  • I have already selected permalink post name
    – HeroWeb512
    Commented Nov 14, 2017 at 11:15
  • then just go to permalinks dont change anything just save changes
    – DHL17
    Commented Nov 14, 2017 at 11:16
  • Your template should be taxonomy-doctor_services.php, else WP will look for services term under Doctor taxonomy. Check here developer.wordpress.org/files/2014/10/wp-hierarchy.png Commented Nov 14, 2017 at 11:17
  • I have saved permalinks after selecting a post name but problem not solved
    – HeroWeb512
    Commented Nov 14, 2017 at 11:18

1 Answer 1

1

Use the_archive_title(); instead of single_cat_title(); and the_archive_description(); instead of category_description();

add this code to functions.php

add_filter('get_the_archive_title', function ($title) {
    return preg_replace('/^\w+: /', '', $title);
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.