Custom post categories
-
Hi
I’ve added a custom post type to my site called ‘suppliers’ and set up categories within that custom post type by adding the following to funtions.php.
function my_custom_post_supplier() { $labels = array( 'name' => _x( 'Suppliers', 'post type general name' ), 'singular_name' => _x( 'Supplier', 'post type singular name' ), 'add_new' => _x( 'Add New', 'book' ), 'add_new_item' => __( 'Add new supplier' ), 'edit_item' => __( 'Edit suppliers' ), 'new_item' => __( 'New supplier' ), 'all_items' => __( 'All suppliers' ), 'view_item' => __( 'View suppliers' ), 'search_items' => __( 'Search suppliers' ), 'not_found' => __( 'No suppliers found' ), 'not_found_in_trash' => __( 'No suppliers found in the Trash' ), 'parent_item_colon' => '', 'menu_name' => 'Suppliers' ); $args = array( 'labels' => $labels, 'description' => 'Holds our products and product specific data', 'public' => true, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), 'has_archive' => true, ); register_post_type( 'supplier', $args ); } add_action( 'init', 'my_custom_post_supplier' );I’ve then got it to list all the categories within supplier by adding the following code to a page template.
<?php $customPostTaxonomies = get_object_taxonomies('supplier'); if(count($customPostTaxonomies) > 0) { foreach($customPostTaxonomies as $supplier) { $args = array( 'orderby' => 'name', 'show_count' => 0, 'pad_counts' => 0, 'hierarchical' => 1, 'taxonomy' => $supplier, 'title_li' => '' ); wp_list_categories( $args ); } } ?>When I click one of these links it goes to
http://www.mysite.co.uk/supplier_category/categorynameWith categoryname being the name of the link I just clicked.
When do this using normal posts (not custom) this then works by going to my archive.php page to detect what category was clicked and to display the posts within that category. Using custom posts I just get page not found.
I’m using a bespoke theme which used _me (underscoresme) as a starting point.
The topic ‘Custom post categories’ is closed to new replies.