WordPress subpages to custom post types

I have created a CPT like this:

add_action( 'init', 'create_media' );
function create_media() {
  $labels = array(
    'name' => _x('Media', 'post type general name'),
    'singular_name' => _x('Media', 'post type singular name'),
    'add_new' => _x('Add New', 'Media'),
    'add_new_item' => __('Add New Media'),
    'edit_item' => __('Edit Media'),
    'new_item' => __('New Media'),
    'view_item' => __('View Media'),
    'search_items' => __('Search Media'),
    'not_found' =>  __('No Media found'),
    'not_found_in_trash' => __('No Media found in Trash'),      
    'parent_item_colon' => __( 'Parent Media' )
  );

  register_post_type( 'media',
    array(
      'labels' => $labels,
      'public' => true,
      'rewrite' => array('slug' => 'media'),
      'capability_type' => 'page',
      'hierarchical' => true,
      'supports' => array( 'title', 'revisions' )
    )
  );
}

In my CPT, I have a custom taxonomy, created like that:

Read More
add_action( 'init', 'create_mediatype' );
function create_mediatype() {
 $labels = array(
    'name' => _x( 'Media types', 'taxonomy general name' ),
    'singular_name' => _x( 'Media type', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Media types' ),
    'all_items' => __( 'All Media types' ),
    'parent_item' => __( 'Parent Media type' ),
    'parent_item_colon' => __( 'Parent Media type' ),
    'edit_item' => __( 'Edit Media type' ),
    'update_item' => __( 'Update Media type' ),
    'add_new_item' => __( 'Add New Media type' ),
    'new_item_name' => __( 'New Media type Name' ),
    'menu_name' => __( 'Media types' ),
  );    

  register_taxonomy('mediatype',array('media'),array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'media' ),
  ));
}

I have 3 types of taxonomy: Photos, Videos and Audios.

What is best way to set up to obtain subpages for each category like this:

…/media/photos
…/media/videos
…/media/audios

I’ve tried to create a page for each with a template page allocated and by setting media as parent. But this doesn’t work.

Thanks

Related posts

Leave a Reply