views:

174

answers:

1

Hello,

I am registering a custom post type like so:

register_post_type('agent_info', array(
                'labels' => array('name' => __('Agents'), 
                           'singular_name' => __('Agent'),
                           'add_new_item' => __('Add New Agent'),
                           'edit_item' => __('Edit Agent'),
                     ),
                    'public' => true,
            '_builtin' => false,
            'query_var' => true,
            'rewrite' => array('slug' => 'agents', 'with_front' => false),
                    'show_ui' => true,
                    'supports' => array('title')
            ));

and when i try to access an agent using '/agents/agent-name-slug' i get a 404 error, but i change agents to agent_info, it works fine. What am i missing to allow the rewrite stuff to work properly?

+1  A: 

Two things to check: are you hooking the post type registration onto init? and are you flushing the rewrite rules each time you change the rewrite slug?

If you're not hooking onto init, you should.

To flush rewrite rules, just go to the permalinks settings page. You don't even need to click save. It'll rewrite the rules as soon as you go there.

Also, I don't know if you realize this, but that won't give you a list view of your post type. To enable that, you have to add this to your init hook:

add_rewrite_rule( 'agents/?$', 'index.php?post_tye=agent_info', 'top' );

After adding that code, go back to the permalinks settings page.

John P Bloch