I am using WAMP with the latest version of WordPress installed. I have a custom post type created using the following…
function register_fruit() {
register_post_type('fruit', array(
'labels' => array(
'name' => __( 'Fruit' ),
),
'public' => true,
'has_archive' => true,
'capability_type' => 'post',
'rewrite' => array("slug" => "/fruit", "with_front" => false),
'supports' => array( 'title', 'editor', 'thumbnail'),
'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
));
}
add_action('init', 'register_fruit', 0 );
This works fine when viewing individual items for example..
www.mydomain.com/fruit/apple
www.mydomain.com/fruit/orange
www.mydomain.com/fruit/pear
But if I try and view the archive pages such as…
www.mydomain.com/fruit
I get a 404, I can’t see where the problem lies, can anyone help?
Have you tried refreshing permalinks?
Settings -> Permalinks (don’t have to change anything)
Then try again?
Remove the leading slash in your rewrite argument, This:
should be:
and your archive will work correctly.
I had this problem and tried all the solutions (flush permalinks, various rewrites, etc) until I stumbled in the WP Codex on
Indeed, I had
'query_var' => true
which caused my problem.I have the same issue using:
I added the “pre_get_posts” action because I was having the same problem as fightstar.