0

I've got a custom post type called "properties" and two custom taxonomies called "type" (office space, retail space, etc.) and "location" (new york, chicago, etc.).

I have created "archive-properties.php" which works beautifully when I go to "mysite.com/properties." And I have "single-properties.php" which works great when I go to "mysite.com/properties/my-single-post."

I've created some dynamic Type and Location navigation menus that populate with all available "types" and "locations" from the taxonomy. And I have a "taxonomy-properties.php" template file. Unfortunately, both "mysite.com/office-space" and "mysite.com/properties/office-space" yield a 404. Same with any of the cities.

I've already tried the Permalinks trick, but it didn't work. And I've already looked at other questions on this topic and gotten no where.

What file do I need to create to make this work, and where does it need to go? Am I expecting too much? Is Wordpress not really set up to work this way? If not, what is the best way to show an "archive" page for my custom taxonomies?

Difficulty: The "type" taxonomy is unlikely to change, since the client only handles office space and retail space. But cities are always being added to the "location" taxonomy, so I can't just create a template file for every city.

UPDATE: Adding the code I used to create the custom post type and taxonomies.

function create_post_type_properties() {
    $labels = array(
        'name'                  => __('Properties', 'properties'),
        'singular_name'         => __('Property', 'properties'),
        'add_new'               => __('Add New', 'properties'),
        'add_new_item'          => __('Add New Property', 'properties'),
        'edit'                  => __('Edit', 'properties'),
        'edit_item'             => __('Edit Property', 'properties'),
        'new_item'              => __('New Property', 'properties'),
        'view'                  => __('View Property', 'properties'),
        'view_item'             => __('View Property', 'properties'),
        'search_items'          => __('Search Properties', 'properties'),
        'not_found'             => __('No Properties found', 'properties'),
        'not_found_in_trash'    => __('No Properties found in Trash', 'properties'),
        'parent_item_colon'     => '',
        'menu_name'             => 'Properties'
    );

    $args = array(
        'labels'        => $labels,
        'description'   => 'Properties & property specific data',
        'public'        => true,
        'menu_position' => 5,
        'supports'      => array('title', 'editor', 'thumbnail', 'custom-fields'),
        'taxonomies'    => array(''),
        'has_archive'   => true,
        'can_export'    => true,
        'menu_icon'     => plugins_url( 'image.png', __FILE__ ),
    );

    register_post_type( 'properties', $args );
}

/* Create custom taxonomy (type) for properties */
function property_type_taxonomy() {
    $labels = array(
        'name'              => _x( 'Property Types', 'taxonomy general name' ),
        'singular_name'     => _x( 'Property Type', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Property Types' ),
        'all_items'         => __( 'All Property Types' ),
        'parent_item'       => __( 'Parent Property Type' ),
        'parent_item_colon' => __( 'Parent Property Type:' ),
        'edit_item'         => __( 'Edit Property Type' ), 
        'update_item'       => __( 'Update Property Type' ),
        'add_new_item'      => __( 'Add New Property Type' ),
        'new_item_name'     => __( 'New Property Type' ),
        'menu_name'         => __( 'Property Types' ),
    );

    $args = array(
        'labels'        => $labels,
        'show_ui'       => true,
        'show_tagcloud' => false,
        'hierarchical'  => true
    );

    register_taxonomy( 'property_type', 'properties', $args );
}

/* Create custom taxonomy (location) for properties */
function property_location_taxonomy() {
    $labels = array(
        'name'              => _x( 'Property Locations', 'taxonomy general name' ),
        'singular_name'     => _x( 'Property Location', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Property Locations' ),
        'all_items'         => __( 'All Property Locations' ),
        'parent_item'       => __( 'Parent Property Location' ),
        'parent_item_colon' => __( 'Parent Property Location:' ),
        'edit_item'         => __( 'Edit Property Location' ), 
        'update_item'       => __( 'Update Property Location' ),
        'add_new_item'      => __( 'Add New Property Location' ),
        'new_item_name'     => __( 'New Property Location' ),
        'menu_name'         => __( 'Property Locations' ),
    );

    $args = array(
        'labels'        => $labels,
        'show_ui'       => true,
        'show_tagcloud' => false,
        'hierarchical'  => true
    );

    register_taxonomy( 'property_location', 'properties', $args );
}
3
  • You shouldn't have to create any files. If no specific template is found, then WP will use index.php template. Could you show us how do you register these custom post types and custom taxonomies? Commented Aug 6, 2013 at 17:36
  • And how do you call these functions? Commented Aug 6, 2013 at 17:44
  • @KrzysiekDróżdż, I add them via add_action on init
    – Paul D
    Commented Aug 6, 2013 at 23:30

2 Answers 2

2

The way taxonomies work with rewrites, is that they have a 'slug'. Look at the codex under register_taxonomy, you will see the 'rewrite' argument. Supply it with array( 'slug' => 'properties/location' ) and refresh your permalinks. Otherwise, it's looking for the following:

mysite.com/property_location/office-space

Refer to @vancoders answer for the template solution.

5
  • Let me state for the record that the answer by @vancoder was very helpful for pointing out my file-naming error. However, this is ultimately the answer that solved the taxonomy/hierarchy/slug problem I came here about. Thanks everyone!
    – Paul D
    Commented Aug 6, 2013 at 23:41
  • Pardon this likely stupid question: the two taxonomies, "type" and "location", can't have the same slug specified in the 'rewrite' argument, right? For example, I can't just say 'properties' for both and get 'mysite.com/properties/office-space' AND 'mysite.com/properties/chicago'? I tried it and it didn't work, but I thought perhaps there was a way to do this, possibly involving 'with_front' and/or 'hierarchical' in the 'rewrite' argument? Thanks in advance...
    – Paul D
    Commented Aug 7, 2013 at 0:18
  • In short, no. You could rejig rewrite rules, but it will cause slower page loads, and major errors should you ever have a location and type with the same slug. Stick with properties/type and properties/location, which will help specify what WP needs to look for (and thus making pages faster. Commented Aug 7, 2013 at 12:55
  • Right on. Thanks. Everything works great now thanks to you and Vancoder. I guess I was just being greedy.
    – Paul D
    Commented Aug 8, 2013 at 18:34
  • Yeah the issue is you'd have 2 different taxonomies and a custom post type all with the same rewrite rule - no good sir! Commented Aug 8, 2013 at 20:01
1

taxonomy-properties.php makes no sense, as properties is your CPT, not your taxonomy.

Try creating taxonomy-property_type.php, etc.

Consulting the hierarchy is often helpful: http://codex.wordpress.org/Template_Hierarchy

7
  • You're probably right, but it still shouldn't cause 404 errors... Commented Aug 6, 2013 at 19:21
  • The URLs he is trying - mysite.com/office-space etc - do not fall inside the hierarchy, so will result in a 404.
    – vancoder
    Commented Aug 6, 2013 at 19:28
  • And now, again, you're probably right. But still these 404 errors have nothing to do with template hierarchy - and this is what you based your answer on. What I mean is - you're answer is probably correct, but a little bit to laconic, so it's not very helpful, I guess. Solving template hierarchy problems won't solve 404 errors (and this is main part of this problem, IMHO). Commented Aug 6, 2013 at 19:33
  • 1
    @KrzysiekDróżdż the question is titled "Template files..." so I suggest this is a pretty perfect answer for the scope of this question. Commented Aug 6, 2013 at 20:02
  • 1
    @PaulD By the way, your explanation of the problem was perfectly adequate. The disagreement was nonsense.
    – vancoder
    Commented Aug 6, 2013 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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