Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've had a look around for this but nothing has came up (perhaps am not searching good enough?) but I'm trying to set a parent on a taxonomy which is loaded from another taxonomy.

For example I have Car Makes and Car Models, when adding a new model I would like to select its parent (Car Make) not another parent within itself.

Makes cannot have any parents, but can have unlimited children, models cannot have any children and there parent must be a make.

Is this possible? Preferably without a plugin.

/* Makes */
$labels = array(
'name' => _x( 'Makes', 'taxonomy general name' ),
    'singular_name' => _x( 'Make', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Makes' ),
    'all_items' => __( 'All Makes' ),
    'parent_item' => __( 'Parent Make' ),
    'parent_item_colon' => __( 'Parent Make:' ),
    'edit_item' => __( 'Edit Make' ),
    'update_item' => __( 'Update Make' ),
    'add_new_item' => __( 'Add New Make' ),
    'new_item_name' => __( 'New Make' ),
);  
register_taxonomy('makes', 'car', array('hierarchical' => false, 'labels' => $labels, 'query_var' => false, 'rewrite' => false, 'with_front' => false));

/* Models */
$labels = array(
'name' => _x( 'Models', 'taxonomy general name' ),
    'singular_name' => _x( 'Model', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Models' ),
    'all_items' => __( 'All Models' ),
    'parent_item' => __( 'Parent Model' ),
    'parent_item_colon' => __( 'Parent Model:' ),
    'edit_item' => __( 'Edit Model' ),
    'update_item' => __( 'Update Model' ),
    'add_new_item' => __( 'Add New Model' ),
    'new_item_name' => __( 'New Model' )
);
register_taxonomy('models', 'car', array('hierarchical' => true, 'labels' => $labels, 'query_var' => false, 'rewrite' => false, 'with_front' => false));

This question is slightly related: Show WordPress Custom Taxonomy Items Based On a Selected Item From Another Custom Taxonomy however I assume the parent/child elements are from one taxonomy? In my case they need to be two separate taxonomies.

share|improve this question
    
Do you definitely need 2 separate taxonomies? This might be simpler with a single hierarchical taxonomy like make_and_model. –  sam May 19 '12 at 20:00
    
I tried it that way first, however its for a client not me and theres a 90% chance they will mess it up :p. –  Elliott May 19 '12 at 20:08
add comment

3 Answers 3

I am not sure, but look at http://codex.wordpress.org/Function_Reference/register_taxonomy_for_object_type - it connect even taxonomies.

If it will not help, your only one solution is combination of custom-taxonomy and custom post type. See http://codex.wordpress.org/Function_Reference/register_post_type

share|improve this answer
    
I've never tried using register_taxonomy_for_object_type I always assumed taxonomies were not stored in the post types array and would fail the assertion that it is a post object. –  Steve Buzonas May 14 '12 at 6:17
add comment

This is something I do rather frequently. WordPress isn't designed for it out of the box currently.

Unfortunately I don't know of a way to do it without a plugin (done properly anyhow, using options is an ugly alternative). I have a standard taxonomy class in a plugin that does the heavy lifting for me. It adds custom tax meta tables to the database and provides an abstract custom taxonomy class.

The taxonomy class handles a metadata registry and automates the creation of meta boxes. It has a few built in meta parameters as well such as parent item. I only use the hierarchical attribute for simple taxonomies (parent is same tax) and built-ins.

Update:

Well, for one I was thinking of my post types with different post object parents, but similar approach.

Looking through some of my past works with taxonomies, what I have done before I created my framework plugin with the taxonomy class is echo a dropdown of the parent terms when editing the taxonomy using the ${taxonomyname}_edit_form_fields hook. You need to provide a callback to the edited_${taxonomyname} hook as well to save your parent data somewhere. You can mark hierarchical to false for both and store the parent id where wordpress would normally store it.

share|improve this answer
    
Thanks for your reply, I've looked into the edit_form_fields hook and that looks the way to go..its a shame it isn't possible to hook onto the "parent" dropdown. –  Elliott May 16 '12 at 20:50
    
I agree, it's something commonly done with WordPress as a CMS. I wish I had the time to port it into core and submit a patch as an enhancement, but I'm working on getting WordPress to run on a cloud with a json backend opposed to mysql. –  Steve Buzonas May 16 '12 at 20:56
add comment

I know you said no plugins, but can I make a suggestion to use a highly configurable plugin which handles custom fields / groups, custom post types, and custom taxonomies?

Really great, simple, and easy to use plugin. No hardcore advertising. Doesn't bog down your wordpress website. This plugin is also developed and updated actively.

Download Types - Custom Fields and Custom Post Types Management

I use this plugin on almost every wordpress install. Should be fantastic for what you're trying to do.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.