custom taxonomy – How to add to taxonomies to a post type

Question

I have sucessefuly add a second taxonomy called tagcat” to a custom post type called “information”,

   add_action ('init','create_information_eventcat_taxonomy','0');
function create_information_eventcat_taxonomy () {
    $taxonomylabels = array(
    'name' => _x('カテゴリー','post type general name'),
    'singular_name' => _x('カテゴリー','post type singular name'),
    'search_items' => __('カテゴリー'),
    'all_items' => __('informationカテゴリー'),
    'parent_item' => __( 'Parent Cat' ),
    'parent_item_colon' => __( 'Parent Cat:' ),
    'edit_item' => __('informationカテゴリーを編集'),
    'add_new_item' => __('informationカテゴリーを書く'),
    'menu_name' => __( 'informationカテゴリー' ),
    );
    $args = array(
    'labels' => $taxonomylabels,
    'hierarchical' => true,
    'has_archive' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'informationcat' )
    );
    register_taxonomy('informationcat','information',$args);
}
// Rewrite Custom Taxonomy to share base slug with Custom Post Type
function rewrite_information_event_category() {
$information_event_category_args = get_taxonomy( 'informationcat' ); // returns an object

$information_event_category_args->show_admin_information_event = true;
$information_event_category_args->rewrite['slug'] = 'information';
$information_event_category_args->rewrite['with_front'] = false;

register_taxonomy( 'informationcat', 'information', (array) $information_event_category_args );
}
add_action( 'init', 'rewrite_information_event_category', 11 );




add_action ('init','create_tagcat_taxonomy','0');
function create_tagcat_taxonomy () {
    $taxonomylabels = array(
    'name' => _x('タグ','post type general name'),
    'singular_name' => _x('タグ','post type singular name'),
    'search_items' => __('タグ'),
    'all_items' => __('タグ'),
    'parent_item' => __( 'Parent Cat' ),
    'parent_item_colon' => __( 'Parent Cat:' ),
    'edit_item' => __('タグを編集'),
    'add_new_item' => __('タグを書く'),
    'menu_name' => __( 'タグ' ),
    );
    $args = array(
    'labels' => $taxonomylabels,
    'hierarchical' => true,
    'has_archive' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'tagcat' )
    );
    register_taxonomy('tagcat','information',$args);
}
// Rewrite Custom Taxonomy to share base slug with Custom Post Type
function rewrite_list_category() {
$list_category_args = get_taxonomy( 'tagcat' ); // returns an object

$list_category_args->show_admin_list = true;
$list_category_args->rewrite['slug'] = 'information';
$list_category_args->rewrite['with_front'] = false;

register_taxonomy( 'tagcat', 'information', (array) $list_category_args );
}
add_action( 'init', 'rewrite_list_category', 11 );

Im having problems dealing with two taxonomies, in the permalinks.
How can I display, the two taxonomies, in two separated taxonomie pages?Its currently only displaying the taxonomie-tagcat.php, but taxonomie-informmationcat.php is returning 404. I guess it has to do with information_rewrites_init(), what should I do?

function information_rewrites_init($post_link, $post = 0){
    add_rewrite_rule('information\/([0-9]+)?(page\/)?([0-9]+)?\/?$', 'index.php?paged=$matches[3]&post_type=information&p=$matches[1]', 'top');
    add_rewrite_rule('information\/([A-Za-z0-9-_]+)\/?(page\/)?([0-9]+)?\/?$', 'index.php?paged=$matches[3]&informationcat=$matches[1]', 'top');
  add_rewrite_rule('information\/([A-Za-z0-9-_]+)\/?(page\/)?([0-9]+)?\/?$', 'index.php?paged=$matches[3]&tagcat=$matches[1]', 'top');
}
add_action('init', 'information_rewrites_init');

0
Fernando Souza 2 months 2022-10-02T20:35:51-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse