除设置外has_archive
您需要设置rewrite
定义CPT时。我替换了$archives
因为您的代码段没有定义它。
$rewrite = array(\'slug\' => \'my-cpt-type\', \'with_front\' => false);
$download_args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\'=> true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => $rewrite,
\'capability_type\' => \'product\',
\'map_meta_cap\' => true,
// Set has_archive to the prefix you want, so the archive is in the right place
\'has_archive\' => \'my-cpt-name/news\',
// Also set rewrite to the prefix you want, which will affect individual posts.
\'rewrite\' => \'my-cpt-name/news\',
\'hierarchical\' => false,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\', \'excerpt\', \'revisions\', \'author\' ),
);
register_post_type( \'my-cpt-type\', $download_args );
您需要:
取消注册post类型(“my-cpt-type”);取消注册CPT,否则WP将不接受您的更改。取消注册时不会丢失任何内容,它只会清除永久链接。
使用上述设置重新注册,然后访问设置>永久链接页面刷新重写规则。然后,您应该拥有所需的结构-在尝试访问新URL之前,请确保清除浏览器缓存。