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() {

        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!


After you add a new custom post type, you usually have to go under Settings->Permalinks and just click save.

  • 1
    It is because Wordpress needs to refresh the rewrite rules, and it doesn't know to do it, unless you visit that page. You don't actually have to click save, just visit the page. – Jake Aug 23 '12 at 1:07
  • Actually I did that. First I wasn't able to get the URL lets say www.mysite.com/listings/kandy/property where [kandy] is a custom taxonomy vlaue. Once I refreshed the URL structure that problem is solved. But the issue is with the www.mysite.com/listing URL which give a 404 error. I made a page with that slug but still is getting that same 404 error. – Ziyan Junaideen Aug 23 '12 at 5:53
  • Could be conflict between the post type and the page? Having the same name can be touchy. – Jake Aug 23 '12 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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