0

General Setup

I'm working on a setup to create a documentary/wiki site for a company. The site should have three different levels of hierarchy and one type of content at the lower end:

  • level 1: area (high level structure, e.g. 'internal stuff' or 'external projects')
  • level 2: topic (main structure, e.g. 'controlling' or 'project xyz')
  • level 3: section (groups the content, for a project this could be 'project management')
  • level 4: content (custom post type that holds the content, basically like pages)

Issue 1

Ideally I have a custom post type for all four level. But is this even possible? Can I have a custom post type under another custom post type? I didn't find anything about this...

Permalinks

So the permalinks should be like this:

mysite.com/area/external-projects

Simply lists all topics in this area, so area is kind of a category for topic

mysite.com/topic/project-xyz

Lists all the sections and the content entries.

Link to section is not needed.

The link to content is tricky and the point where I need help:

mysite.com/topic/my-topic/content/this-is-my-content

Issue 2

So, the permalinks for the content should include the topic and the content. Is this even possible if the section (the hierarchy between them) is not in the permalink?

1 Answer 1

0

You can do this with custom hierarchical taxonomy and use it for your custom post type.

Register the Taxonomy area for the post type content using the init action hook:

function wporg_register_taxonomy_area() {
   $labels = array(
     'name'              => _x( 'Areas', 'taxonomy general name' ),
     'singular_name'     => _x( 'Area', 'taxonomy singular name' ),
     'search_items'      => __( 'Search Areas' ),
     'all_items'         => __( 'All Areas' ),
     'parent_item'       => __( 'Parent Area' ),
     'parent_item_colon' => __( 'Parent Area:' ),
     'edit_item'         => __( 'Edit Area' ),
     'update_item'       => __( 'Update Area' ),
     'add_new_item'      => __( 'Add New Area' ),
     'new_item_name'     => __( 'New Area Name' ),
     'menu_name'         => __( 'Area' ),
   );
   $args   = array(
     'hierarchical'      => true, // make it hierarchical (like categories)
     'labels'            => $labels,
     'show_ui'           => true,
     'show_admin_column' => true,
     'query_var'         => true,
     'rewrite'           => [ 'slug' => 'area' ],
   );
   register_taxonomy( 'area', [ 'content' ], $args );
}
add_action( 'init', 'wporg_register_taxonomy_area' );

Register custom post type content using the init action hook:

function my_custom_content_item() {
    $labels = array(
        'name'               => _x( 'Content', 'post type general name' ),
        'singular_name'      => _x( 'Content', 'post type singular name' ),
        'menu_name'          => 'Content'
    );
    $args = array(
        'labels'        => $labels,
        'public'        => true,
        'has_archive'   => true,
        'taxonomies'    => array( 'area' ),
        'show_in_rest'  => true,
    );
    register_post_type( 'content', $args );

} 
add_action( 'init', 'my_custom_content_item' );

Adds the registered taxonomy area to object type content.

function attach_area_to_content() {
    register_taxonomy_for_object_type( 'area', 'content' );
}
add_action('init','attach_area_to_content');

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.