0

I currently have two post types, Posts and Tutorials. Tutorials are grouped into sets of tutorials within Courses, which I have created with a custom Course taxonomy. Courses can belong to multiple categories, as can Posts. These categories have been created using the built-in category taxonomy. Posts will never belong to a course and should have no association to them.

How can I set up this hierarchy, primarily the linking of a custom Course taxonomy to the built-in Category taxonomy?

0

When you register your custom post type you can set which taxonomies will be registered for this post type. So you can register your custom 'Course' taxonomy and the built-in 'Category' taxonomy with your custom post type 'Tutorials'. And posts will just be registered with 'Category'.

function tutorial_setup_post_type() {
    $args = array(
        'public'    => true,
        'label'     => __( 'Tutorials', 'textdomain' ),
        'taxonomies' => array(
            'category',
            'course'
        ),
    );
    register_post_type( 'tutorial', $args );
}
add_action( 'init', 'tutorial_setup_post_type' );

https://developer.wordpress.org/reference/functions/register_post_type/

  • I'm familiar with how to link post types to taxonomies. The preference is to link the two taxonomies -- courses and categories in this case, since it's less important to know the category in relation to the post. Is this not at all possible? – chm Oct 13 '17 at 20:33
  • Taxonomies are designed to be linked to post_types not other taxonomies. I don't really understand what you are trying to do. But maybe you could use post_meta or a custom non-public post_type to achieve what you want. – ngearing Oct 14 '17 at 21:43
  • Thanks for the tips -- I'm trying to convert an existing website with the aforementioned database structure to Wordpress. I think I see now how it can be done with a combination of post types and taxonomies. – chm Oct 17 '17 at 13:55

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.