gpt4 book ai didi

wordpress - 帖子类型分层

转载 作者:行者123 更新时间:2023-12-05 03:14:21 27 4
gpt4 key购买 nike

我有一个问题,升级到 wordpress 4.0 后,我的自定义帖子类型不再有效,这是我注册自定义帖子类型的方法:

function my_post_type() {
$labels = array(
'name' => 'Staff'
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 20,
'menu_icon' => null,
'capability_type' => 'post',
'hierarchical' => true,
'supports' => array('title','editor','thumbnail','custom-fields','page-attributes'),
'has_archive' => false,
'rewrite' => false,
'query_var' => true,
'can_export' => true
);
register_post_type('my_staff', $args);
}
add_action('init', 'my_post_type');

问题是此帖子类型的永久链接会出现 404,如果我将“hierarchical”设置为 false,一切正常,但问题是我需要将“hierarchical”设置为 true,对此有任何解决方案吗?

最佳答案

我今天早些时候升级到 WP 4.0 后遇到了同样的问题——我的一种分层自定义帖子类型的单个帖子在升级后显示 404。

我深入研究了 WP 核心以查看可能导致问题的更改并发现了这一点:

https://core.trac.wordpress.org/changeset/28803

回到以前的代码为我解决了 404 问题。无法判断这是否表明我自己的 CPT 实现不佳或 Core 中的此更改出现无法预料的错误。也就是说,如果遇到此问题的其他人想尝试此解决方案,这是一个相对简单的更改。

将/wp-includes/query.php 中的第 2558 行替换为:

if ( ! $ptype_obj->hierarchical ) {

为此:

if ( ! $ptype_obj->hierarchical || strpos($q[ $ptype_obj->query_var ], '/') === false ) { 

关于wordpress - 帖子类型分层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25740115/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com