我已经尝试了所有我能找到的解决方案,但我仍然被困在这里。This post 有一个很好的彻底的调试方法,但它没有帮助。
部分原因可能是因为我想the Flatpack theme 改变它的行为。我们现在锁定了这个主题。我这样做是为了使投资组合和服务CPT分层:
add_action( \'init\', \'lf_modify_post_types\', 999999 );
function lf_modify_post_types() {
if ( post_type_exists( \'portfolio\' ) ) {
$args = get_post_type_object( \'portfolio\' );
$args->rewrite[\'slug\'] = \'portfolio\';
$args->rewrite[\'with_front\'] = false;
$args->hierarchical = true;
$args->supports[] = \'page-attributes\';
$args->query_var = true;
register_post_type( \'portfolio\', $args );
}
if ( post_type_exists( \'services\' ) ) {
$args = get_post_type_object( \'services\' );
$args->rewrite[\'slug\'] = \'services\';
$args->rewrite[\'with_front\'] = false;
$args->hierarchical = true;
$args->supports[] = \'page-attributes\';
$args->query_var = true;
register_post_type( \'services\', $args );
}
}
据我所知,这可以确保所有相关的CPT设置都是正确的(包括设置
query_var
这似乎是这个问题的常见“解决方案”)。上面末尾的portfolio CPT对象转储给出了以下结果:
stdClass Object (
[labels] => stdClass Object
(
[name] => Portfolio
[singular_name] => Portfolio
[add_new] => Add Portfolio Item
[add_new_item] => Add New Portfolio Item
[edit_item] => Edit
[new_item] => New Portfolio Item
[view_item] => View Portfolio Item
[search_items] => Search Portfolio Items
[not_found] => No portfolio items found
[not_found_in_trash] => No portfolio items found in Trash
[parent_item_colon] =>
[all_items] => Portfolio
[menu_name] => Portfolio
[slug] => portfolio
[name_admin_bar] => Portfolio
)
[description] =>
[public] => 1
[hierarchical] => 1
[exclude_from_search] =>
[publicly_queryable] => 1
[show_ui] => 1
[show_in_menu] => 1
[show_in_nav_menus] => 1
[show_in_admin_bar] => 1
[menu_position] =>
[menu_icon] => http://languagefutures.localhost/wp-content/themes/language-futures/ocmx/images/icons/portfolio-icon.png
[capability_type] => post
[map_meta_cap] => 1
[register_meta_box_cb] =>
[taxonomies] => Array
(
)
[has_archive] =>
[rewrite] => Array
(
[slug] => portfolio
[with_front] =>
[pages] => 1
[feeds] =>
[ep_mask] => 1
)
[query_var] => portfolio
[can_export] => 1
[delete_with_user] =>
[_builtin] =>
[_edit_link] => post.php?post=%d
[name] => portfolio
[cap] => stdClass Object
(
[edit_post] => edit_post
[read_post] => read_post
[delete_post] => delete_post
[edit_posts] => edit_posts
[edit_others_posts] => edit_others_posts
[publish_posts] => publish_posts
[read_private_posts] => read_private_posts
[read] => read
[delete_posts] => delete_posts
[delete_private_posts] => delete_private_posts
[delete_published_posts] => delete_published_posts
[delete_others_posts] => delete_others_posts
[edit_private_posts] => edit_private_posts
[edit_published_posts] => edit_published_posts
[create_posts] => edit_posts
)
[label] => Portfolio
)
刷新规则,仍然:
http://languagefutures.localhost/portfolio/project-and-themes/ (正常工作)http://languagefutures.localhost/portfolio/project-and-themes/who-do-you-think-you-are/ (404)
我在后一个URL上使用了重写规则检查器插件,它显示:
portfolio/(.+?)(/[0-9]+)?/?$ index.php?portfolio=$matches[1]&page=$matches[2] portfolio
(.?.+?)(/[0-9]+)?/?$ index.php?pagename=$matches[1]&page=$matches[2] page
好吧,这一切都是应该的。使用查询监视器插件,以下是正在运行的相关查询:
SELECT ID, post_name, post_parent, post_type
FROM k3bex_posts
WHERE post_name IN (\'project-and-themes\',\'who-do-you-think-you-are\')
AND (post_type = \'portfolio\'
OR post_type = \'attachment\')
Caller:
get_page_by_path()-
WP_Query->get_posts()
WP_Query->query()
WP->query_posts()
WP->main()
wp()
Returns: 2
SELECT k3bex_posts.*
FROM k3bex_posts
WHERE 1=1
AND (k3bex_posts.ID = \'1493\')
AND k3bex_posts.post_parent = 0
AND k3bex_posts.post_type = \'portfolio\'
ORDER BY k3bex_posts.post_date DESC
Caller:
WP_Query->get_posts()-
WP_Query->query()
WP->query_posts()
WP->main()
wp()
Returns: 0
SELECT ID
FROM k3bex_posts
WHERE post_name LIKE \'who-do-you-think-you-are%\'
AND post_type = \'portfolio\'
AND post_status = \'publish\'
Caller:
redirect_guess_404_permalink()-
redirect_canonical()
do_action(\'template_redirect\')
Returns: 1
最引人注目的是第二个。1493确实是子页面的正确ID。为什么查询指定post\\u parent=0?我将继续调查此事,但如果有人经历过这样的事情并幸存下来,那么给他们一些提示就太好了。