最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Custom taxonomy returns 404 even with saving permalinks

programmeradmin1浏览0评论

I'm trying to register a custom posttype and custom post type taxonomy. But when I create a term and click the button "view" to see the custom taxonomy page it returns a 404. I've tried resaving the permalinks a 1000 times, doesn't work.

function build_blog_post_type() {
        register_post_type (
            'blog',
            array (
                'labels'=> array (
                    'name'                      => 'Blog',
                    'singular_name'     => 'Blog bericht',
                    'add_new_item'      => 'Blog bericht toevoegen',
                    'add_new'                   => 'Blog bericht toevoegen',
                    'all_items'             => 'Alle blog berichten'
                ),
                'public'        => true,
                'menu_position' => 2,
                'menu_icon'   => 'dashicons-id-alt',
                'supports' => array('title'),
            )
        );

        register_taxonomy(
        'blog_taxonomy',
        'blog',
        array (
            'label'                 => 'Welke taxonomy',
                'name'                  => 'Welke taxonomy',
                'singular_name' => 'Welke taxonomy',
                'edit_item'     => 'Bewerk taxonomy',
                'add_new_item'  => 'Nieuwe taxonomy toevoegen',
                'menu_name'     => 'Welke taxonomy',
                'show_in_nav_menus' => false,
                'public'                => true,
        )
      );
    }
    add_action('init', 'build_blog_post_type');

URL I'm trying to acces: mydomain.test/blog_taxonomy/test-taxonomy

I have an 404.php with a specific main ID and a index.php with its own specific main ID, so I can easly see which is returned. There is no indication index.php is used

I'm trying to register a custom posttype and custom post type taxonomy. But when I create a term and click the button "view" to see the custom taxonomy page it returns a 404. I've tried resaving the permalinks a 1000 times, doesn't work.

function build_blog_post_type() {
        register_post_type (
            'blog',
            array (
                'labels'=> array (
                    'name'                      => 'Blog',
                    'singular_name'     => 'Blog bericht',
                    'add_new_item'      => 'Blog bericht toevoegen',
                    'add_new'                   => 'Blog bericht toevoegen',
                    'all_items'             => 'Alle blog berichten'
                ),
                'public'        => true,
                'menu_position' => 2,
                'menu_icon'   => 'dashicons-id-alt',
                'supports' => array('title'),
            )
        );

        register_taxonomy(
        'blog_taxonomy',
        'blog',
        array (
            'label'                 => 'Welke taxonomy',
                'name'                  => 'Welke taxonomy',
                'singular_name' => 'Welke taxonomy',
                'edit_item'     => 'Bewerk taxonomy',
                'add_new_item'  => 'Nieuwe taxonomy toevoegen',
                'menu_name'     => 'Welke taxonomy',
                'show_in_nav_menus' => false,
                'public'                => true,
        )
      );
    }
    add_action('init', 'build_blog_post_type');

URL I'm trying to acces: mydomain.test/blog_taxonomy/test-taxonomy

I have an 404.php with a specific main ID and a index.php with its own specific main ID, so I can easly see which is returned. There is no indication index.php is used

Share Improve this question edited Mar 10, 2020 at 15:05 mhaklander asked Mar 10, 2020 at 14:34 mhaklandermhaklander 11 bronze badge 12
  • 1 Could you post an example link you are using to access the taxonomy? – Wacław Jacek Commented Mar 10, 2020 at 14:44
  • @WacławJacek I'm using the "view" button in admin, it gives me: mydomain.test/blog_taxonomy/test-taxonomy – mhaklander Commented Mar 10, 2020 at 14:45
  • Are you sure it is a 404 error? Maybe the taxonomy link is working correctly and there just are no posts in that taxonomy? – Wacław Jacek Commented Mar 10, 2020 at 14:55
  • @WacławJacek yes definitely. It even renders my custom 404 page.. :( – mhaklander Commented Mar 10, 2020 at 14:56
  • Do you have a custom 404.php template or is your index.php catching 404 errors? In the latter case, it is possible that if you do not have a taxonomy page template, WordPress is displaying the index.php file containing a "404 error" message instead. – Wacław Jacek Commented Mar 10, 2020 at 14:59
 |  Show 7 more comments

1 Answer 1

Reset to default 0

I've found my solution.. In my functions.php I found the following functions which returns a 404 on several types:

  function remove_wp_archives(){
    //If we are on category or tag or date or author archive
    if( is_category() || is_tag() || is_date() || is_author() || is_tax() ) {
      global $wp_query;
      $wp_query->set_404(); //set to 404 not found page
      status_header(404);
      nocache_headers();
    }
  }
  add_action('template_redirect', 'remove_wp_archives');
发布评论

评论列表(0)

  1. 暂无评论