admin管理员组文章数量:1310513
I've created a custom taxonomy register as the code below, but it does not find the taxonomy-specialty.php nor archive.php templates (page not found error).
I did following (as recommended by other threads found on SE and the web): - re-save the permalinks - find the taxonomy settings page in wp-admin and when I hover over 'View' it points me to 'mysite/events/specialties/footology' for a 'Footology' taxonomy entry I created for a post of type 'event' - so the URL is as expected. However when visiting the link still get page not found error.
$specialty_args = array(
'hierarchical' => false,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => 'Specialty',
'singular_name' => 'Specialty',
'search_items' => 'Search specialties',
'all_items' => 'All specialties',
'edit_item' => 'Edit specialty',
'update_item' => 'Update specialty',
'add_new_item' => 'Add new specialty',
'new_item_name' => 'New specialty name',
'menu_name' => 'Specialties',
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => 'specialty',
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'events/specialties', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/specialties/"
'hierarchical' => false
),
);
register_taxonomy('specialty', 'event', $specialty_args);
register_taxonomy_for_object_type('specialty', 'event'); //says in under 'Usage' to do this
I don't know what is wrong. Help appreciated, thank you!
I've created a custom taxonomy register as the code below, but it does not find the taxonomy-specialty.php nor archive.php templates (page not found error).
I did following (as recommended by other threads found on SE and the web): - re-save the permalinks - find the taxonomy settings page in wp-admin and when I hover over 'View' it points me to 'mysite/events/specialties/footology' for a 'Footology' taxonomy entry I created for a post of type 'event' - so the URL is as expected. However when visiting the link still get page not found error.
$specialty_args = array(
'hierarchical' => false,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => 'Specialty',
'singular_name' => 'Specialty',
'search_items' => 'Search specialties',
'all_items' => 'All specialties',
'edit_item' => 'Edit specialty',
'update_item' => 'Update specialty',
'add_new_item' => 'Add new specialty',
'new_item_name' => 'New specialty name',
'menu_name' => 'Specialties',
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => 'specialty',
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'events/specialties', // This controls the base slug that will display before each term
'with_front' => false, // Don't display the category base before "/specialties/"
'hierarchical' => false
),
);
register_taxonomy('specialty', 'event', $specialty_args);
register_taxonomy_for_object_type('specialty', 'event'); //says in https://codex.wordpress/Function_Reference/register_taxonomy under 'Usage' to do this
I don't know what is wrong. Help appreciated, thank you!
Share Improve this question asked Oct 21, 2015 at 4:12 gvantogvanto 1431 silver badge8 bronze badges 2 |2 Answers
Reset to default 1The page not found error doesn't mean that the template file is not found/used. Note that a URL returns a 404 status header (not found), then 404.php is used (or index.php if 404.php doesn't exist).
I think your real problem is that you have not flushed the rewrite rules after the taxonomy has been registered. To do it, follow these steps:
Manually: go to settings->permalinks and click the save button (you don't need to change anything, just click the save button).
Auto: in your plugin, use flush_rewrite_rules()
during plugin activation hook (never use flush_rewrite_rules()
on every page load). For example:
register_activation_hook( __FILE__, 'cyb_plugin_activation' );
function cyb_plugin_activation() {
cyb_register_taxonomy();
flush_rewrite_rules();
}
add_action( 'init', 'cyb_register_taxonomy' );
function cyb_register_taxonomy() {
$specialty_args = array(
'hierarchical' => false,
// This array of options controls the labels displayed in the WordPress Admin UI
'labels' => array(
'name' => 'Specialty',
'singular_name' => 'Specialty',
'search_items' => 'Search specialties',
'all_items' => 'All specialties',
'edit_item' => 'Edit specialty',
'update_item' => 'Update specialty',
'add_new_item' => 'Add new specialty',
'new_item_name' => 'New specialty name',
'menu_name' => 'Specialties',
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => 'specialty',
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'events/specialty', // This controls the base slug that will display before each term (renamed to specialty from specialties)
'with_front' => false, // Don't display the category base before "/specialties/"
'hierarchical' => false
),
);
register_taxonomy('specialty', 'event', $specialty_args);
register_taxonomy_for_object_type('specialty', 'event');
}
register_deactivation_hook( __FILE__, 'cyb_plugin_deactivation' );
function cyb_plugin_deactivation() {
// Flush the rewrite rules also on deactivation
flush_rewrite_rules();
}
'show_ui' => true,
'show_admin_column' => true,
'query_var' => 'specialty',
'has_archive' => true, //make sure you have added this one
What is your archive name? What is your archive url? Actually, your archive file name should be like that archive-specialty.php, your post type archive url will be like this yourdomain/events/specialties. I have tested, it should work on yours.
If you are not sure about custom post type, use wordpress type plugin or use wordpress generator
本文标签: Custom taxonomy archive templates not found
版权声明:本文标题:Custom taxonomy archive templates not found 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741824958a2399587.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
init
action? are there posts assigned to the term you are viewing? what is your post type's URL structure and is it hierarchical?var_dump($wp_query)
in the 404 template and look at what WordPress is querying for. – Milo Commented Oct 22, 2015 at 5:04