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

12
  • 1
    Could you post an example link you are using to access the taxonomy? Mar 10 '20 at 14:44
  • @WacławJacek I'm using the "view" button in admin, it gives me: mydomain.test/blog_taxonomy/test-taxonomy
    – Mooksz
    Mar 10 '20 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? Mar 10 '20 at 14:55
  • @WacławJacek yes definitely. It even renders my custom 404 page.. :(
    – Mooksz
    Mar 10 '20 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. Mar 10 '20 at 14:59
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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.