Skip to main content
added 3603 characters in body
Source Link

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 );
}

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 );
}
Source Link

Template files for Custom Post Type and Taxonomy

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.