Reputation: 31
Please help.
There is a custom post type "films" and a taxonomy "genres" with the following structure of permalinks:
http://example.com/films/film-1/
http://example.com/genres/genre-1/
To address http://example.com/genres/ get the 404 error.
I want need to type links http://example.com/films/genres/genre-1/ and the list of movies posts at http://example.com/films/genres/.
Thank you in advance for your help.
My code:
function films_catalog() {
$labels = array(
'name' => 'Films catalog',
'singular_name' => 'Film',
'add_new' => 'Add film',
'add_new_item' => 'Add new film',
'edit_item' => 'Edit film',
'new_item' => 'New film',
'all_items' => 'All films',
'view_item' => 'Show films',
'search_items' => 'Search films',
'not_found' => 'No films.',
'not_found_in_trash' => 'No films.',
'menu_name' => 'Films'
);
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'has_archive' => true,
'menu_icon' => get_stylesheet_directory_uri() .'/img/films_icon.png',
'menu_position' => 20,
'supports' => array( 'title', 'editor', 'comments', 'author', 'thumbnail'),
);
register_post_type('films', $args);
}
add_action( 'init', 'films_catalog' );
function create_films_taxonomies(){
$labels = array(
'name' => 'Genres',
'singular_name' => 'Genres',
'search_items' => 'Search genres',
'popular_items' => 'Popular genres',
'all_items' => 'All genres',
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => 'Edit genre',
'update_item' => 'Update genre',
'add_new_item' => 'Add new genre',
'new_item_name' => 'New genre name',
'separate_items_with_commas' => 'Genres list',
'add_or_remove_items' => 'Add or remove genres',
'choose_from_most_used' => 'Popular genres',
'menu_name' => 'Genres',
);
register_taxonomy('genres', array('films'), array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genres' ),
));
}
add_action( 'init', 'create_films_taxonomies', 0 );
Upvotes: 1
Views: 45
Reputation: 27
function films_catalog() {
$labels = array(
'name' => 'Films catalog',
'singular_name' => 'Film',
'add_new' => 'Add film',
'add_new_item' => 'Add new film',
'edit_item' => 'Edit film',
'new_item' => 'New film',
'all_items' => 'All films',
'view_item' => 'Show films',
'search_items' => 'Search films',
'not_found' => 'No films.',
'not_found_in_trash' => 'No films.',
'menu_name' => 'Films'
);
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'has_archive' => true,
'menu_icon' => get_stylesheet_directory_uri() .'/img/films_icon.png',
'menu_position' => 20,
'supports' => array( 'title', 'editor', 'comments', 'author', 'thumbnail'),
);
register_post_type('films', $args);
flush_rewrite_rules();
}
add_action( 'init', 'films_catalog' );
function create_films_taxonomies(){
$labels = array(
'name' => 'Genres',
'singular_name' => 'Genres',
'search_items' => 'Search genres',
'popular_items' => 'Popular genres',
'all_items' => 'All genres',
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => 'Edit genre',
'update_item' => 'Update genre',
'add_new_item' => 'Add new genre',
'new_item_name' => 'New genre name',
'separate_items_with_commas' => 'Genres list',
'add_or_remove_items' => 'Add or remove genres',
'choose_from_most_used' => 'Popular genres',
'menu_name' => 'Genres',
);
register_taxonomy('genres', array('films'), array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genres' ),
));
}
add_action( 'init', 'create_films_taxonomies', 0 );
this works fine all the way copy and paste in for file
Upvotes: 1
Reputation: 27
add this line
flush_rewrite_rules( false );
after
register_post_type('films', $args);
if not solve this please go to settings permalink first save to custom and run then change it to post-type.
Hope this will solve the issue.
Upvotes: 0