404 for a custom taxonomy?

404 for a custom taxonomy?



Why do I get 404 for my custom taxonomy?


add_action('init', 'custom_taxonomy_flush_rewrite');
function custom_taxonomy_flush_rewrite()
global $wp_rewrite;
$wp_rewrite->flush_rules();


add_action('init', 'create_publication_categories');
function create_publication_categories()
$args = array(
'label' => __('Categories'),
'has_archive' => true,
'hierarchical' => true,
'rewrite' => array(
'slug' => 'topics',
'with_front' => false
),
);
$postTypes = array(
'publication'
);
$taxonomy = 'publication';
register_taxonomy($taxonomy, $postTypes, $args);



So I have the template called taxonomy-publication.php, but I still get 404.


taxonomy-publication.php



I have reset the permalink following this. And other answers such as this and this.



But I still get 404. Any ideas what I have missed?




1 Answer
1



You use the same slug publication for custom taxonomy and custom post type. Slug should be unique.


publication



Another thing (not related with 404) is the flush_rules. As you can read here flush on the init hook is bad idea.


flush_rules


init



Important:


init


activation


deactivation



Example



Flush rules on theme activation:


add_action( 'after_switch_theme', 'custom_taxonomy_flush_rewrite' );
function custom_taxonomy_flush_rewrite()
global $wp_rewrite;
$wp_rewrite->flush_rules();





Thanks for the answer again. btw, how do I flush properly then if flush on the init hook is bad idea.?
– laukok
Aug 20 at 20:18


flush on the init hook is bad idea





You can use after_switch_theme action hook or use option to store flush status. Before $wp_rewrite->flush_rules() check if option (e.g get_option('flush_done', 0) == 0) exists and save after flush (update_option('flush_done', 1)). @laukok
– nmr
Aug 20 at 20:41



after_switch_theme


$wp_rewrite->flush_rules()


get_option('flush_done', 0) == 0


update_option('flush_done', 1)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

How to change the default border color of fbox? [duplicate]

ᵟᴈ,ᴘᵨᵷᴬ ᴳᵵᴂᴮᵇᵘᴀᴈᴵᵪᵬᴵᴬᴢᵔᵧ,ᵄᴠᴹᵔᴍᵲᵜᴫᵄᵋᴅ,ᵪᵢᵠ ᴡᵗ,ᵷᴝᵲ ᴖᴤᵡ,ᴎ,ᴚ ᵡᵪᵀ,ᴐᵉ,ᵿᴂ,ᴽᴽᵍᵟᵍᴠᵓᵯᴞᵅᵛᵢ,ᴐᴁ ᵺᴉᵸᴵᴶᵄᴪᵷ,ᴌᴠᴗᴚ,ᵟᵺᵳᴝᴉᴰ,ᵹᵥ ᵂᴴ,ᴵ,ᵉᵿ ᴕᵕ,ᴃᴡᴒᵐᴇᴳᵅᵞᴒᴝᴳᴋᴗᵢᵶᵢᵅᴣᴑᵘᵷᵾᴍᴔᴵ,ᴢᴘ,ᴮᵫᴘ,ᵳ,ᴩᵓᴞ