1
votes

I have created a custom post type called protocols and registered a few taxonomies for that custom post type to allow the customer a filterable/searchable list of posts. For some reason, the taxonomy categories are not showing up in the admin screen post list for the custom post type. screenshot here: http://demo.agexpressions.com/img/admin-screen.png

I have used the 'show_admin_column' => true line when registering all the taxonomies but the columns are still blank! Hopefully someone with sharp eyes and more knowledge than me can help me diagnose this issue! Code below:

// hook into the init action and call create_protocol_taxonomies when it fires
add_action( 'init', 'create_protocol_taxonomies', 0 );

// create three taxonomies - primary and disease categories, and status for the post type "protocols"

function create_protocol_taxonomies() {
// Add new taxonomy for Primary Category
$primarylabels = array(
    'name'              => _x( 'Primary', 'taxonomy general name' ),
    'singular_name'     => _x( 'Primary', 'taxonomy singular name' ),
    'search_items'      => __( 'Search Primary' ),
    'all_items'         => __( 'All Primaries' ),
    'menu_name'         => __( 'Primary' ),
);

$primaryargs = array(
    'hierarchical'      => true,
    'labels'            => $primarylabels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'primary' ),
);

register_taxonomy( 'primary', 'protocols', $primaryargs );

// Add new taxonomy for Disease Category
$diseaselabels = array(
    'name'              => _x( 'Disease', 'taxonomy general name' ),
    'singular_name'     => _x( 'Disease', 'taxonomy singular name' ),
    'search_items'      => __( 'Search Disease' ),
    'all_items'         => __( 'All Diseases' ),
    'menu_name'         => __( 'Disease' ),
);

$diseaseargs = array(
    'hierarchical'      => true,
    'labels'            => $diseaselabels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'disease' ),
);

register_taxonomy( 'disease', 'protocols', $diseaseargs );

// Add new taxonomy for Status
$statuslabels = array(
    'name'              => _x( 'Status', 'taxonomy general name' ),
    'singular_name'     => _x( 'Status', 'taxonomy singular name' ),
    'search_items'      => __( 'Search Status' ),
    'all_items'         => __( 'All Status' ),
    'menu_name'         => __( 'Status' ),
);

$statusargs = array(
    'hierarchical'      => true,
    'labels'            => $statuslabels,
    'show_ui'           => true,
    'show_admin_column' => TRUE,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'status' ),
);

register_taxonomy( 'status', 'protocols', $statusargs );
}


add_action( 'init', 'protocols_init', 0 );
// Creates Protocols Custom Post Type
function protocols_init() {
$protocolsargs = array(
  'label' => 'Protocols',
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => array('slug' => 'protocol'),
    'query_var' => true,
    'menu_icon' => 'dashicons-book-alt',
'menu_position' => 5,
'has_archive' => true,
'taxonomies' => array('primary', 'disease', 'status'),
    'supports' => array(
        'title',
        'editor',
        'revisions')
    );
register_post_type( 'protocols', $protocolsargs );
}

Noticed something else also. If you click the quick edit link on a post and assign categories to it, they then show up in the columns!

However, if you go to the full edit screen, the categories you just assigned are there, but if you make changes or even update without making changes, the categories disappear from the admin columns again...

So confused, someone please take a look at my code and see if I'm doing something wrong!! I've done hours of research, searching on wordpress support forums and the codex, and come up short. No help from a post on wordpress forums either, it's been up for over a month.

Could it be something as simple as a function out of order? Is the custom post type or taxonomy being initiated too late?

2

2 Answers

0
votes

Actually, I found the solution. After searching through the database via phpAdmin, I noticed that there were duplicates of the taxonomy terms. The older versions were from a first failed attempt at creating the custom post type and taxonomies.

I deleted all the custom taxonomy terms from the database and then went back to Wordpress and created them again, essentially giving me a fresh list of terms. They now show up correctly in the admin post list, as well as on the site itself.

Now, I'm still not sure WHY the duplicate terms were the issue, just that they were. Maybe the residual terms from my first failed attempt were conflicting with the new terms, because the term name was the same but they were attached to different taxonomies.