I started with a fresh template and added a Post Type
according to specification at GenerateWP.
I then added a taxonomy to the custom post type, also according to the above-referenced website:
// Register Custom Taxonomy
function addIssuesTaxonomy() {
$labels = array(
'name' => _x( 'Issues', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Issue', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Issues', 'text_domain' ),
'all_items' => __( 'All Issues', 'text_domain' ),
'parent_item' => __( 'Parent Issue', 'text_domain' ),
'parent_item_colon' => __( 'Parent Issue:', 'text_domain' ),
'new_item_name' => __( 'New Issue Name', 'text_domain' ),
'add_new_item' => __( 'Add New Issue', 'text_domain' ),
'edit_item' => __( 'Edit Issue', 'text_domain' ),
'update_item' => __( 'Update Issue', 'text_domain' ),
'view_item' => __( 'View Issue', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate issues with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove issues', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Issues', 'text_domain' ),
'search_items' => __( 'Search Issues', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
'no_terms' => __( 'No items', 'text_domain' ),
'items_list' => __( 'Issues list', 'text_domain' ),
'items_list_navigation' => __( 'Issues list navigation', 'text_domain' ),
);
$rewrite = array(
'slug' => 'issues',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy( 'issues', array( 'articles' ), $args );
}
add_action( 'init', 'addIssuesTaxonomy', 0 );
I then saved the permalinks in this structure http://xxx/sample-post/
, but no matter what, the newly added taxonomy does not show up at http://xxx/issues
. Instead I get a 404. Navigating to /articles/issues/
also results in 404.
What am I missing in order to display all issues
found in the newly created taxonomy?
I started with a fresh template and added a Post Type
according to specification at GenerateWP.
I then added a taxonomy to the custom post type, also according to the above-referenced website:
// Register Custom Taxonomy
function addIssuesTaxonomy() {
$labels = array(
'name' => _x( 'Issues', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Issue', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Issues', 'text_domain' ),
'all_items' => __( 'All Issues', 'text_domain' ),
'parent_item' => __( 'Parent Issue', 'text_domain' ),
'parent_item_colon' => __( 'Parent Issue:', 'text_domain' ),
'new_item_name' => __( 'New Issue Name', 'text_domain' ),
'add_new_item' => __( 'Add New Issue', 'text_domain' ),
'edit_item' => __( 'Edit Issue', 'text_domain' ),
'update_item' => __( 'Update Issue', 'text_domain' ),
'view_item' => __( 'View Issue', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate issues with commas', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove issues', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ),
'popular_items' => __( 'Popular Issues', 'text_domain' ),
'search_items' => __( 'Search Issues', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
'no_terms' => __( 'No items', 'text_domain' ),
'items_list' => __( 'Issues list', 'text_domain' ),
'items_list_navigation' => __( 'Issues list navigation', 'text_domain' ),
);
$rewrite = array(
'slug' => 'issues',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'rewrite' => $rewrite,
);
register_taxonomy( 'issues', array( 'articles' ), $args );
}
add_action( 'init', 'addIssuesTaxonomy', 0 );
I then saved the permalinks in this structure http://xxx/sample-post/
, but no matter what, the newly added taxonomy does not show up at http://xxx/issues
. Instead I get a 404. Navigating to /articles/issues/
also results in 404.
What am I missing in order to display all issues
found in the newly created taxonomy?
1 Answer
Reset to default 0There's no such page in WordPress. /issues/
doesn't exist. All WordPress URLs display either a single post/page, or a list of posts/pages (search, date archives, category archives etc.). So there's no way WordPress will list terms. If you create a new issue, then that will be accessible at /issues/issue-name/
, but nothing will exist on /issues/
by itself.
If you want to list all issues, then the simplest method would be to create a page called Issues, then create a custom page template that lists all terms in the Issues taxonomy. You can do this with get_terms()
:
$issues = get_terms( [ 'taxonomy' => 'issues' ] );
if ( ! is_wp_error( $issues ) && $issues ) {
foreach( $issues as $issue ) {
echo $issue->name; // Name of issue.
echo get_term_link( $issue ); // URL to articles in that issue.
}
}