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 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!

share|improve this question
add comment

1 Answer 1

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

share|improve this answer
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
    
thanks for the clarification –  Jeff Langston Aug 23 '12 at 1:53
    
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
add comment

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.