Custom taxonomy returns 404

时间:2016-04-16 作者:mihajlo

当我访问我的自定义分类页面时,我得到了一个404页面。自定义分类法称为“制造商”。我还有一个名为“产品”的cpt。

EDIT 1:这与cpt重写有关。如果禁用重写,分类法工作正常。

注意事项:

permalinks flush无助于模板分类制造商。php exists WP version is 4.4.2 WP category具有基“kategorie”

  • post url设置为“post name”
  • cpt应具有“pretty url”(无任何前缀)
    • 这是cpt的“product”:

              function product_post_type() {
      
          $labels = array(
              \'name\'                  => _x( \'Products\', \'Post Type General Name\' ),
              \'singular_name\'         => _x( \'Product\', \'Post Type Singular Name\' ),
              \'menu_name\'             => __( \'Products\' ),
              \'name_admin_bar\'        => __( \'Product\' ),
              \'archives\'              => __( \'Products Archives\' ),
              \'parent_item_colon\'     => __( \'Parent Product:\' ),
              \'all_items\'             => __( \'All Products\' ),
              \'add_new_item\'          => __( \'Add New Product\' ),
              \'add_new\'               => __( \'Add New\' ),
              \'new_item\'              => __( \'New Product\' ),
              \'edit_item\'             => __( \'Edit Product\' ),
              \'update_item\'           => __( \'Update Product\' ),
              \'view_item\'             => __( \'View Product\' ),
              \'search_items\'          => __( \'Search Product\' ),
              \'not_found\'             => __( \'Product Not found\' ),
              \'not_found_in_trash\'    => __( \'Product Not found in Trash\' ),
              \'featured_image\'        => __( \'Featured Image\' ),
              \'set_featured_image\'    => __( \'Set featured image\' ),
              \'remove_featured_image\' => __( \'Remove featured image\' ),
              \'use_featured_image\'    => __( \'Use as featured image\' ),
              \'insert_into_item\'      => __( \'Insert into product\' ),
              \'uploaded_to_this_item\' => __( \'Uploaded to this product\' ),
              \'items_list\'            => __( \'Products list\' ),
              \'items_list_navigation\' => __( \'Products list navigation\' ),
              \'filter_items_list\'     => __( \'Filter products list\' ),
          );
          $args = array(
              \'label\'                 => __( \'Products\' ),
              \'description\'           => __( \'Product Description\' ),
              \'labels\'                => $labels,
              \'supports\'              => array( \'title\', \'editor\', \'thumbnail\' ),
              \'taxonomies\'            => array( \'category\' ),
              \'hierarchical\'          => false,
              \'public\'                => true,
              \'show_ui\'               => true,
              \'show_in_menu\'          => true,
              \'menu_position\'         => 5,
              \'show_in_admin_bar\'     => true,
              \'show_in_nav_menus\'     => true,
              \'can_export\'            => true,
              \'exclude_from_search\'   => false,
              \'publicly_queryable\'    => true,
              \'query_var\' => true,
              \'capability_type\'       => \'post\',
              \'rewrite\' => array(\'slug\' => \'/\'),
              \'has_archive\' => true
          );
          register_post_type( \'product\', $args );
      }
      add_action( \'init\', \'product_post_type\', 0 );
      
      这是自定义分类“制造商”:

          function manufacturer_taxonomy(){
          $labels = array(
              \'name\'              => _x( \'Herstellers\', \'taxonomy general name\' ),
              \'singular_name\'     => _x( \'Hersteller\', \'taxonomy singular name\' ),
              \'search_items\'      => __( \'Search Hersteller\' ),
              \'all_items\'         => __( \'All Hersteller\' ),
              \'parent_item\'       => __( \'Parent Hersteller\' ),
              \'parent_item_colon\' => __( \'Parent Hersteller:\' ),
              \'edit_item\'         => __( \'Edit Hersteller\' ),
              \'update_item\'       => __( \'Update Hersteller\' ),
              \'add_new_item\'      => __( \'Add New Hersteller\' ),
              \'new_item_name\'     => __( \'New Hersteller Name\' ),
              \'menu_name\'         => __( \'Hersteller\' ),
          );
      
          register_taxonomy( \'manufacturer\', \'product\', array(
              \'hierarchical\'      => true,
              \'labels\'            => $labels,
              \'show_ui\'           => true,
              \'show_admin_column\' => true,
              \'query_var\'         => true,
              \'rewrite\' => array(
                  \'slug\' => \'hersteller\',
                  \'with_front\' => false
              ),
          ));
      }
      add_action(\'init\',\'manufacturer_taxonomy\',0);
      
      任何想法都很好。

    1 个回复
    SO网友:Caspar

    你不能有一个重写段\'/\'. 请注意,使用\'\', 你会发现它到处浮动,对于最新的WordPress版本也不起作用。如果你想要像这样的urlhttp://domain.com/custom-post, 没有防弹的解决方案,但这个问题的答案会给你一些线索:Remove slug from custom post type post URLs

    相关推荐

    Permalinks setting

    所以,我知道这是一个基本的问题,但奇怪的是,它对我不起作用。我想要的:https://example.com/blog/thema/类别名称/postname(用于帖子)https://example.com/blog/thema/类别名称(适用于类别)以下是我的设置:遗憾的是,这行不通。以下是有关在什么设置下工作的详细信息:Posts: /blog/thema/%category%/%postname%/ + Category: blog/thema = 分类工作,帖子获取404Posts: /%cat