So I have a custom post type called “shoes”. I know I can display these if I create a template called archive-shoes.php (for the listing) and single-shoes.php (for each individual post), and the listing can be shown by going to http://localhost/shoes, which will then list ALL posts of type “shoes”.
So far so good.
Now, each shoe is either “outdoor” or “indoor”. I could do this through adding categories, or custom fields. Either way…..
Question is, if I want to show ONLY the outdoor shoes, what URL should I use? Am I going to have to use http://localhost/shoes/?type=outdoor (and then do the filtering in archive-shoes.php) or is this functionality already built in in WordPress and there a way I can directly call it?
I thought about creating category-outdoor.php but it seems it will then not list the custom post types, only REGULAR posts with category “outdoor”.
I may be overthinking it but what’s the most efficient way of listing all posts of a custom type with a certain category?
I admit, I have only a *basic* working knowledge of the full power of custom taxonomies because I haven’t used them that much, but this sounds like a perfect application for them.
That would work if the custom taxonomy would be a dropdown field in the admin, but from the looks of it, it’s not…just a text field in which the admin can enter any value they like.
I also don’t have much experience with taxonomies (I still get confused what the difference is between a custom taxonomy and a custom field) but I’d prefer it to be a custom field. I think.
wptuts has a tutorial to change the taxonomies to radio button selections: http://wp.tutsplus.com/tutorials/creative-coding/how-to-use-radio-buttons-with-taxonomies/
I still think taxonomies would be your best approach to this. I always visualize taxonomies as “custom categories” for custom post types.. when registering the taxonomy, you specify that it only shows up in the “shoes” post type, and it becomes a category filter for that post type.
This reply has been reported for inappropriate content.
@senff are you using Custom Post Types UI or is this just manual? What I’ve always done inside of the plugin was change the taxonomy type to “hierarchical” and they seem to function the way you are describing.
@ChrisP: OK, so I’ve tried the taxonomies route (even though I would have preferred to keep it a custom field, but let’s see if I can get there). I see your point.
@JoshWhite: yes, through Custom Post Types UI, and with the “hierarchical” setting it gets the select boxes.
Now…….. I gave my custom post a custom taxonomy setting of “indoor”, but going to http://localhost/indoor doesn’t give me the list of all indoor shoes. :(
> Now…….. I gave my custom post a custom taxonomy setting of “indoor”, but going to http://localhost/indoor doesn’t give me the list of all indoor shoes. :(
Have you flushed the permalinks?
side note: I’m sure it’s possible to use custom fields for this, but keeping a clean URL structure, and keeping the backend work _relatively_ low, I think the taxonomies route would be better IMHO
Check out the Answer on http://wordpress.stackexchange.com/questions/8100/custom-taxonomy-list-page
I am not sure if it is exactly what you are trying to do, but you can create page templates to call those custom taxonomies that are in your custom post type. I was trying to do something similar and someone (who is better at WP modifications than me) told me it wasn’t possible and I needed to use page templates instead and modified the queries accordingly. The article I linked above was something I found that kinda explains the situation.
@scottnix: although that article didn’t give me the exact answer (I’m not creating custom posts and taxonomies with code, but using a plugin), it did point me in the right direction.
So the functionality finally works.
Not 100% satisfied with having to do taxonomies (I would prefer that the client could change all their settings as custom fields, now they have to use custom fields AND taxonomies) but I guess this is the next best thing.
I’ve quickly created this for you. It’s a plugin that creates Custom Post Type of “Shoes” and has two taxonomies attached: “type” and “color”… Type can be “Indoor or Outdoor” or you may choose to change this… you can create more by adding `$taxonomies = array();` to `$taxonomies = array();`. Just copy the contents on this file and save it in your plugins folder. Hope that helps, Alen.
CODE REMOVED see bellow >> edited few mistakes…
few gotchas: you need to flush the permalinks (going to Settings >> Permalink and clicking on Permalink twice) or you [could add automatic flushing](http://codex.wordpress.org/Function_Reference/flush_rewrite_rules).
I’ve tested the code with WordPress 3.6-beta3-24306. Newest as of today.
When using menu editor to add items, make sure to click on “screen options” top right corner to display all post types, so you can select them for your menu.
Plugin Name: Custom Post Type & Taxonomies
Plugin URI: http://#
Description: Custom Post Type & Taxonomies Description
Author: Alen Abdula
Author URI: http://www.alenabdula.com
public function __construct()
public function register_post_type()
$args = array(
‘labels’ => array(
‘name’ => ‘Shoes’,
‘singular_name’ => ‘Shoe’,
‘menu_name’ => ‘Shoes’,
‘all_items’ => ‘Shoes’,
‘add_new’ => ‘Add New Shoe’,
‘add_new_item’ => ‘Add New Shoe’,
‘edit_item’ => ‘Edit Shoe’,
‘new_item’ => ‘New Shoe’,
‘view_item’ => ‘View Shoe’,
‘search_items’ => ‘Search Shoes’,
‘not_found’ => ‘No Shoes Found’,
‘not_found_in_trash’ => ‘No Shoes in Trash’,
‘parent_item_colon’ => ‘Shoes’
‘description’ => ‘My Cool Custom Post Type for Shoes’,
‘public’ => true,
‘exclude_from_search’ => false,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_nav_menus’ => true,
‘show_in_menu’ => true,
‘menu_position’ => 5,
‘map_meta_cap’ => true,
‘hierarchical’ => true,
‘supports’ => array(
‘has_archive’ => true,
‘rewrite’ => array(
‘slug’ => ‘shoes’,’with_front’ => true,
‘feeds’ => true,’pages’ => true
‘query_var’ => ‘shoe’
public function taxonomies()
$taxonomies = array();
I actually have the need for a lot more custom fields and taxonomies (the problem in this thread was a reduced test case) and I’m using a plugin to create custom post types and custom taxonomies, so I can’t directly use your code. However it will definitely help me with creating custom code myself, by seeing how you did this, so thanks :)
@senff just simply create a page template, Then you will apply it to a page. Put the following Code into the page template that you created, This code will allow you to query all of the post from any designated category.
query_posts( array ( ‘category_name’ => ‘my-category-slug’, ‘posts_per_page’ => -1 ) );
This is the only possible way that i know how to do this. I do know for a fact that it is not possible to accomplish this strictly through using a plugin simply because the plugin developers must have overlooked this functionality and did not add this to the plugins.
You must be logged in to reply to this topic.