I am creating a website for a real-estate agent and have encountered an issue which I assume is Custom Taxonomy and Post Types.
Custom Post Type: Property Taxonomy: District Example URL: www.mywebsite.com/listing/[district]/[title], www.mywebsite.com/listings/kandy/house1
Current Situation: It works, but when I go to www.mywebsite.com/listings I get a 404 error. I expect to show all 'Property' type posts here.
I then made a custom page name (slug) 'listings' hoping to give it a template that is similar to the blog that users can brows up and down. But still it shows 404 error.
(WordPress.org and StackExchange got me up to here, but I am kind of lost at the moment, which I thought of asking the question.)
Code is a mess, but here is what I got so far:
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type('post_mozeej_property',
array (
'labels' => array (
'name' => __('Properties'),
'singular_name' => __('Property'),
'add_new' => __('Add New'),
'add_new_item' => __('Create New Property'),
'edit' => __('Edit'),
'edit_item' => __('Edit Property'),
'new_item' => __('New Property'),
'view' => __('View Properties'),
'view_item' => __('View Property'),
'search_items' => __('Search Properties'),
'not_found' => __('No properties found'),
'not_found_in_trash' => __('No properties found in trash')
),
'description' => __('Add new real-estate property from here!'),
'public' => TRUE,
'show_ui' => TRUE,
'capability_type' => 'post',
//'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments'),
'publicly_queryable' => TRUE,
'exclude_from_search' => FALSE,
//'menu_icon' => get_stylesheet_directory() . '/images/property_icon.png',
'_builtin' => false,
'rewrite' => array( 'slug' => 'listings/%tx_mozeej_district%', 'with_front' => true ),
'query_var' => true
)
);
$labels = array(
'name' => _x( 'CR Districts', 'taxonomy general name' ),
'singular_name' => _x( 'CR District', 'taxonomy singular name' ),
'search_items' => __( 'Search CR Districts' ),
'all_items' => __( 'All CR Districts' ),
'parent_item' => __( 'Parent CR Districts' ),
'parent_item_colon' => __( 'Parent CR Districts:' ),
'edit_item' => __( 'Edit CR District' ),
'update_item' => __( 'Update CR District' ),
'add_new_item' => __( 'Add New CR District' ),
'new_item_name' => __( 'New CR District Name' ),
'menu_name' => __( 'CR District' ),
);
register_taxonomy('tx_mozeej_district', array('post_mozeej_property'), array(
'hierarchical' => TRUE,
'labels' => $labels,
'show_ui' => TRUE,
'query_var' => TRUE,
//'rewrite' => true,
'rewrite' => array( 'slug' => '', 'with_front' => TRUE ),
));
function filter_post_type_link($link, $post) {
if ($post->post_type != 'post_mozeej_property')
return $link;
if ($cats = get_the_terms($post->ID, 'tx_mozeej_district'))
$link = str_replace('%tx_mozeej_district%', array_pop($cats)->slug, $link);
return $link;
}
add_filter('post_type_link', 'filter_post_type_link', 10, 2);
}
Have I done any thing wrong? Will be great if some one can help me.
Thanks in advance!