【问题标题】:Wordpress Custom Post and Taxonomy 404Wordpress 自定义帖子和分类法 404
【发布时间】:2016-02-04 22:38:52
【问题描述】:

我正在 wordpress 网站上建立一个常见问题解答部分。我有一个名为 faq 的自定义帖子类型,它有一个名为 faq-category 的自定义分类。我还使用了一个名为 Custom Post Type Permalinks 的插件。

我正在尝试实现以下永久链接结构:

  • domain.com/faq
  • domain.com/faq/category
  • domain.com/faq/category/question-title

到目前为止,我似乎只能完成 2/3 的工作。所以下面的例子给了我:

  • domain.com/faq
  • domain.com/faq/category

和 `domain.com/faq/category/question-title 上的 404

如果我改变:'slug' => 'faq' 到 'slug' => '' 我重写的自定义分类。我在分类页面上收到 404 错误,并且单个帖子可以正常工作。

谢谢

/**
 * Custom taxonomys
 */
function create_faq_tax() {
    register_taxonomy(
        'faq-category',
        'faq',
        array(
            'label' => __( 'Category' ),
            'rewrite' => array( 'slug' => 'faq', 'with_front' => false, 'hierarchical' => true ),
            'hierarchical' => true
        )
    );
}

add_action( 'init', 'create_faq_tax' );


/**
 * FAQ Custom post type
 */
function create_faq_post_type() {
    register_post_type( 'faq',
        array(
            'labels' => array(
                'name' => __( 'FAQ\'s' ),
                'singular_name' => __( 'FAQ' ),
                'add_new' => 'Add new FAQ',
                'add_new_item' => 'Add a new FAQ',
                'edit_item' => 'Edit FAQ',
            ),
            'public' => true,
            'publicly_queryable' => true,
            'hierarchical' => true,
            'taxonomies' => array('faq-category'),
            'has_archive' => true,
            'menu_icon' => 'dashicons-feedback',
            'rewrite' => array( 'slug' => 'faq', 'with_front' => false ),
            'query_var' => true,
        )
    );


}
add_action( 'init', 'create_faq_post_type' );

【问题讨论】:

  • 我自己的自定义帖子类型(啤酒)和类似的分类法(啤酒/风格)遇到了同样的问题。如果我将 slug 设置为 beer/style 它会抛出 404,但如果我将 slug 设置为 style 税收页面可以工作,尽管不是我想要的永久链接结构。

标签: wordpress custom-post-type permalinks custom-taxonomy


【解决方案1】:

创建新的自定义帖子类型或分类后,您必须重新生成永久链接:wp-admin/options-permalink.php。按“保存更改”按钮

【讨论】:

  • 您是否尝试在此处生成自定义帖子类型 (generatewp.com/post-type)?
  • 所以问题似乎是我想使用相同的永久链接 /faq
猜你喜欢
  • 2012-01-01
  • 2011-07-24
  • 2015-06-07
  • 2013-08-03
  • 2017-09-22
  • 2014-07-12
  • 2012-01-06
  • 2011-09-24
  • 1970-01-01
相关资源
最近更新 更多