Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress 未找到自定义帖子类型自定义分类法_Wordpress_Custom Post Type_Permalinks_Custom Taxonomy - Fatal编程技术网

Wordpress 未找到自定义帖子类型自定义分类法

Wordpress 未找到自定义帖子类型自定义分类法,wordpress,custom-post-type,permalinks,custom-taxonomy,Wordpress,Custom Post Type,Permalinks,Custom Taxonomy,我在我的网站上创建了一个名为Homes的自定义帖子类型,它工作正常。我创建了一个名为Availability Category的自定义分类法,并在其中创建了一个名为Availability Now的分类法。分类显示在我的Wordpress后端,但是当我在homes/available now查看分类时,我得到一个404错误 以下是我的自定义帖子类型的代码: register_post_type( 'Homes', array( 'labels' => array(

我在我的网站上创建了一个名为Homes的自定义帖子类型,它工作正常。我创建了一个名为Availability Category的自定义分类法,并在其中创建了一个名为Availability Now的分类法。分类显示在我的Wordpress后端,但是当我在homes/available now查看分类时,我得到一个404错误

以下是我的自定义帖子类型的代码:

register_post_type( 'Homes',
    array(
        'labels' => array(
            'name' => __( 'Homes' ),
            'singular_name' => __( 'Homes Item' ),
            'add_new_item' => __('Add New Homes Item'),
            'edit_item' => __('Edit Homes Item'),
            'new_item' => __('New Homes Item'),
        ),
        'supports' => array('title', 'thumbnail', 'editor'),
        'taxonomies' => array('homes-category'),
        'public' => true,
        'has_archive' => false,
        'show_in_nav_menus'   => TRUE,
        'show_in_menu'        => TRUE,
        'rewrite' => array( 
            'slug' => 'homes',
            'with_front' => false,
            'hierarchical' => false,

            ),
    )
);
以及自定义分类法的代码:

register_taxonomy(
    'homes-category',
    'homes',
    array(
        'hierarchical' => true,
        'label' => __( 'Availability Category' ),
        'rewrite' => array(
            'slug' => 'homes',
            'with_front' => false,
        ),
    )
);

有人能帮忙吗?我已经找了好几个小时的解决办法,但到目前为止,我所尝试的都没有奏效。任何帮助都将不胜感激。

只需访问WP Admin>Settings>permalinks,即可刷新你的永久链接


现在,查看是否仍然使用404..

检查是否有使用相同slug的冲突页面/帖子(即:是否创建了名为“homes”的页面)。如果您这样做了,请删除它们,并确保清空垃圾箱

问题在于,您为自定义帖子类型“homes”指定了与分类法“homes category”相同的重写段塞

要解决您的问题,只需将用于注册自定义帖子类型的代码更改为:

register_post_type( 'Homes',
    array(
        'labels' => array(
            'name' => __( 'Homes' ),
            'singular_name' => __( 'Homes Item' ),
            'add_new_item' => __('Add New Homes Item'),
            'edit_item' => __('Edit Homes Item'),
            'new_item' => __('New Homes Item'),
        ),
        'supports' => array('title', 'thumbnail', 'editor'),
        'taxonomies' => array('homes-category'),
        'public' => true,
        'has_archive' => false,
        'show_in_nav_menus'   => TRUE,
        'show_in_menu'        => TRUE,
        'rewrite' => array(
            'slug' => 'home', //remove the "s" so that it's not fighting with Taxonomy
            'with_front' => false,
            'hierarchical' => false,

            ),
    )
);

然后重新访问您的永久链接页面,然后重试。现在好的是,您还重新获得了创建一个名为“homes”的页面的能力,通过该页面,您可以为其创建自定义模板。我已经对所有这些进行了测试,并且效果良好。:)

我也有同样的问题。我做了一个自定义post类型“products”和自定义分类“products”,当我试图访问www.domain.com/products时,这让我损失了404个错误。网址www.domain.com/products/product-01还可以

因此,您必须将自定义帖子类型重命名为“product”,将CTP重命名为“products”,这样它们就不同了。首先删除自定义文章类型和自定义分类法。然后注册新的CPT和CTP 用不同的名字

CPT-自定义邮政类型
CTP-自定义分类类型

感谢您的响应。我已经试过很多次了,但我还是得到了404。如果我将permalinks设置为默认值,那么页面仍然可以工作。我只得到404当他们被设置为张贴名称。我有一个网页名为家园。我删除了它并将其从垃圾桶中清空,但我仍然收到404错误。执行此操作后,您是否再次访问永久链接设置?是的。我甚至将其设置为默认值,然后返回到post类型,仍然得到404。我不知道如何解决这个问题。我做了您建议的更改,但当我转到homes/available-now时仍然得到404。您是否为“available-now”分类法分配了一个家?我不确定将一个家分配给“available-now”分类法是什么意思。我确实发现,如果我把注册分类代码放在自定义post类型代码之上,它就可以工作了。奇怪的是,因为在我的Functions.php中,我让它按照您最初的顺序排列。我的意思是,在新创建的自定义帖子类型中,您是否在发布之前选择了分类法。将分类法移到自定义帖子类型上方最初是可行的,但我意识到这样做并不能完成我需要它做的事情。是的,我在出版之前选择了分类法。