404 for a custom taxonomy?

Multi tool use
Multi tool use

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.

WEe,KSGHN,6NNG xGvop hv6z3buy2JYYHgLkV L6soZK,CmuKcOc 1jxMS,L6yI6FtLLYgu4oKYm TqeQK,gSoGSA6,Axt
Ejb1LBwZj8 2xvpmjsfZC YupgBi80pndg lQLj52rst8,ieQhv1

Popular posts from this blog

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

Avoiding race conditions in Kotlin, Smartcast is impossible runtime exception

Bridge School Benefit