0

I'm not sure if this possible, but I'd like to be able to show my taxonomies within the admin area of my custom post type so that WordPress users can sort the posts my e.g. subject.

Picture here shows what I mean by custom post type admin area

Here's my code for my custom post type and taxonomies

register_post_type( 'courses',
    array(
    'labels' => array(
      'name' => __( 'Courses' ),
      'singular_name' => __( 'Course' )
    ),
    'public' => true,
    'has_archive' => false,
    'rewrite' => array('slug' => 'courses/%subject%'),
    )
);
}

function themes_taxonomy() {
register_taxonomy(
    'campuses',  // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    'courses',    // post type name
    array(
        'hierarchical' => true,
        'label' => 'Campuses', // display name
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'campus',    // This controls the base slug that will display before each term
            'with_front' => false  // Don't display the category base before
        )
    )
);

register_taxonomy(
    'ages',  // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    'courses',    // post type name
    array(
        'hierarchical' => true,
        'label' => 'Ages', // display name
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'ages',    // This controls the base slug that will display before each term
            'with_front' => false  // Don't display the category base before
        )
    )
);

register_taxonomy(
    'subject',  // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    'courses',    // post type name
    array(
        'hierarchical' => true,
        'label' => 'Subjects', // display name
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'subjects',    // This controls the base slug that will display before each term
            'with_front' => false  // Don't display the category base before
        )
    )
);
} add_action( 'init', 'themes_taxonomy');
0

As documented, you can set the show_admin_column argument of register_taxonomy() to true to do this:

'show_admin_column'
(bool) Whether to display a column for the taxonomy on its post type listing screens. Default false.

For example:

register_taxonomy(
    'subject', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    'courses', // post type name
    array(
        'label'             => 'Subjects', // display name
        'show_admin_column' => true,
        'hierarchical'      => true,
        'query_var'         => true,
        'rewrite'           => array(
            'slug'       => 'subjects', // This controls the base slug that will display before each term
            'with_front' => false, // Don't display the category base before
        ),
    )
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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