WP: custom post type, rewrite url giving 404
صفحه اصلي

WP: custom post type, rewrite url giving 404

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?

how to use accordian menu in wordpress


Change format of “0 Comments and 0 Reactions” in wordpress
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?. In wordpress 3.0 how do you get the default Custom Field UI for Custom Post types? If you're not hooking onto init, you should.. Can anybody send me links of some good tutorial about wordpress development [closed] To flush rewrite rules, just go to the permalinks settings page. BuddyPress slug prefixYou don't even need to click save. Removing href from dynamic item?It'll rewrite the rules as soon as you go there.. wordpress - unique theme for different pages Also, I don't know if you realize this, although this won't commit you a list view of your post type. Very strange problem with Wordpress BlogTo enable that, you have to add this also to your init hook:.
add_rewrite_rule( 'agents/?$', 'index.php?post_type=agent_info', 'top' ); 
After adding this code, go back to the permalinks settings page..

86 out of 100 based on 71 user ratings 346 reviews