Yes, you don't need a custom taxonomy, but a custom post type for courses, and probably a custom taxonomy for courses categories.
In WordPress post types are containers for a certain type of information: every information type is a post type.
E.g. Posts are a type and Pages are another type. Every post type (container) contain some informations: an author, a title, a date, a summary (excerpt)... If you need other custom informations (like age-span) you can use custom post fields.
After that, you can group this containers using taxonomies. WordPress has 2 taxonomies (group) that are used to group the standard post type: categories and tags.
When you create your own post type, you can also create your custom taxonomies as well and use them to group your post. Is possible group the CPTs (Custom Post Types) using the core taxonomies, but in most cases is better define custom taxonomies for custom post types.
To create a CPT or custom taxonomies you don't need plugins: in the functions.php
file of the theme or in a plugin you can use register_post_type
and register_taxonomy
to create a CPT and a taxonomy respectively.
Both CPT and custom taxonomy has an option hierachical
.
When setted to true
for CPT it creates a post type like standard pages, where a post can have a parent, on the countrary, when setted to false it creates a post like the standard post type, where posts can't have parent. The UI created for hierachical and non-hierachical post type is very similar.
A hierachical custom taxonomy is very similar to categories, a non-hierachical one will be similar to post tag. The UI generated by WordPress for hierachical and non hierachical taxonomies is different: in the edit post screen you can choose hierachical taxonomy terms using checkboxes, the non hierachical are chosen using a text field with auto suggestion feature.
Regarding your case a typical code example can be:
function courses_with_cats() {
$course_labels = array(
'name' => 'Courses',
'singular_name' => 'Course',
'add_new' => 'Add New',
'add_new_item' => 'Add New Course',
'edit_item' => 'Edit Course',
'new_item' => 'New Course',
'all_items' => 'All Courses',
'view_item' => 'View Course',
'search_items' => 'Search Courses',
'not_found' => 'No Course found',
'not_found_in_trash' => 'No Courses found in Trash',
'parent_item_colon' => '',
'menu_name' => 'Courses'
);
$course_args = array(
'labels' => $course_labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'course' ),
'capability_type' => 'post',
'has_archive' => 'courses',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','author','thumbnail','excerpt', 'comments')
);
$course_cat_labels = array(
'name' => 'Courses Category',
'singular_name' => 'Course Category',
'search_items' => 'Search Category',
'all_items' => 'All Categories',
'parent_item' => 'Parent Category',
'parent_item_colon' => 'Parent Category:',
'edit_item' => 'Edit Category',
'update_item' => 'Update Category',
'add_new_item' => 'Add New Category',
'new_item_name' => 'New Category Name',
'menu_name' => 'Courses Category',
);
$course_cat_args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'courses/category'),
);
register_post_type( 'course', $course_args );
register_taxonomy( 'courses-cat', array('course'), $course_cat_args );
}
add_action( 'init', 'courses_with_cats' );
This code is all you need to register a post type with its own custom taxonomy. This code register a non hierachical post type (like standard posts) with a hierachical custom taxonomy (like standard categories).
Using this standard setup, the url for the archives of courses is something like: http://example.com/courses/
. Using http://example.com/courses/category/a-category
is shown an archive of all coursesthat belongs to the category with slug "a-category" (probably category name is "A Category").
Look in Codex for the arguments you can use for both register_post_type
and register_taxonomy
.
For register_post_type
note that supports
argument change what is shown in post edit screen.