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 looked at several posts on here trying to crack this. I think it's simple for someone who knows more. The details:

Theme: Custom theme built on Roots starter
WP: 3.8.1
Custom Post Type: pre_owned_cars

My custom post types work well - I'm used to doing those. The taxonomy however is tripping me up. I have it working with the code in my functions.php file, but I can't figure out how to display a taxonomy. I've created taxonomy.php and updated permalinks.

Here's my functions.php code for the taxonomy - I'm trying to name the taxonomy "type":

// add tags to pages
add_action( 'init', 'register_taxonomy_types' );

function register_taxonomy_types() {

$labels = array( 
    'name' => _x( 'Types', 'types' ),
    'singular_name' => _x( 'Type', 'types' ),
    'search_items' => _x( 'Search Types', 'types' ),
    'popular_items' => _x( 'Popular Types', 'types' ),
    'all_items' => _x( 'All Types', 'types' ),
    'parent_item' => _x( 'Parent Type', 'types' ),
    'parent_item_colon' => _x( 'Parent Type:', 'types' ),
    'edit_item' => _x( 'Edit Type', 'types' ),
    'update_item' => _x( 'Update Type', 'types' ),
    'add_new_item' => _x( 'Add New Type', 'types' ),
    'new_item_name' => _x( 'New Type', 'types' ),
    'separate_items_with_commas' => _x( 'Separate types with commas', 'types' ),
    'add_or_remove_items' => _x( 'Add or remove Types', 'types' ),
    'choose_from_most_used' => _x( 'Choose from most used Types', 'types' ),
    'menu_name' => _x( 'Types', 'types' ),
);

$args = array( 
    'labels' => $labels,
    'public' => true,
    'show_in_nav_menus' => true,
    'show_ui' => true,
    'show_tagcloud' => true,
    'show_admin_column' => false,
    'hierarchical' => true,

    'rewrite' => array( 
        'slug' => 'used-cars', 
        'with_front' => true,
        'hierarchical' => true
    ),
    'query_var' => true
);

register_taxonomy( 'types', array('pre-owned-cars'), $args );
}

Any help GREATLY appreciated!

share|improve this question
1  
Is the taxonomy showing up in the admin area correctly? –  Andrew Bartel Jan 30 at 1:56
    
describe "not working". you've named your taxonomy types, and given it the slug used-cars, so a single term will be /used-cars/term-name/. have you created a term and assign it to a post? note that taxonomies aren't like post types- there is no single archive, it's archives for each term. –  Milo Jan 30 at 2:10
    
Okay, so the slug combined with the term is generating a page, but instead of showing the CPTs with this term or taxonomy, it's printing this on the page: wp_list_categories( array( 'taxonomy' => 'register_taxonomy_type' ) ); wp_list_categories( array( 'taxonomy' => 'register_taxonomy_type' ) ); (thanks for the help!) –  Theater Eleven Jan 30 at 2:41
    
Per the last comment, your problem appears to be with your theme template-- a PHP syntax error I'd guess. Post the code for that template. –  s_ha_dum Jan 30 at 3:49
    
<?php while (have_posts()) : the_post(); ?> wp_list_categories( array( 'taxonomy' => 'register_taxonomy_type' ) ); <?php endwhile; ?> –  Theater Eleven Jan 30 at 4:22

1 Answer 1

I don't think the taxonomy is registered with your custom post type. Please check this or may be i'm wrong: if your custom post type is registered with this name: 'pre_owned_cars' , your taxonomy registration is incorrect: it should be register_taxonomy('types', array('pre_owned_cars'), $args);

share|improve this answer
    
I changed it - thanks! The page is pulling fields from the CPT, but only the basic three, see here: shopsupercars.com/used-cars/suv –  Theater Eleven Jan 30 at 5:26
    
I want to display like this: shopsupercars.com/pre-owned-car-inventory-johnson-city –  Theater Eleven Jan 30 at 5:26
    
I'm not getting it.. Sorry... Please elaborate once again.. –  Raajen Jan 30 at 5:32
    
No problem - thanks for the help. The taxonomy is working, but I want to pull only specific fields from the custom post type the taxonomy is registered to. For example, the CPT is for a car. I want taxonomy.php to display the make, model and year fields of the CPT. Doe that make sense? –  Theater Eleven Jan 30 at 5:38
    
you can print the fields value like this: echo get_post_meta($post->ID, 'field_name', true); –  Raajen Jan 30 at 5:44

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.