我的普通帖子发布到domain/notes/
, 所以对于自定义帖子,我可以设置with_front
适当地避免在CPT之前使用notes
.
但是,有没有一种方法我可以“将它们推下一个级别”,以便它们发布到域/程序/?
示例:如果我创建的CPThosts
, 我希望将单个条目发布为domain/programs/hosts/post-name
.
我的普通帖子发布到domain/notes/
, 所以对于自定义帖子,我可以设置with_front
适当地避免在CPT之前使用notes
.
但是,有没有一种方法我可以“将它们推下一个级别”,以便它们发布到域/程序/?
示例:如果我创建的CPThosts
, 我希望将单个条目发布为domain/programs/hosts/post-name
.
您可以尝试slug
agument下rewrite
的参数register_post_type()
功能:
add_action( \'init\', \'egister_hosts_post_type\' );
function register_hosts_post_type() {
$args = array(
// ....
\'rewrite\' => array( \'slug\' => \'programs/hosts\' ),
);
register_post_type( \'hosts\', $args );
}
由于这会影响重写规则,您应该在激活/停用插件时刷新它们:add_action( \'init\', \'cyb_register_hosts_post_type\' );
function cyb_register_hosts_post_type() {
$args = array(
// ....
\'rewrite\' => array( \'slug\' => \'programs/hosts\' ),
);
register_post_type( \'hosts\', $args );
}
register_activation_hook( __FILE__, \'cyb_activation_hook\' );
function cyb_activation_hook() {
cyb_register_hosts_post_type();
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, \'cyb_deactivation_hook\' );
function cyb_deactivation_hook() {
flush_rewrite_rules();
}
我正在构建一个插件,该插件将用于单个站点,并依赖于add_rewrite_rule 要工作,需要打开永久链接。打开它们并不困难,因为它只是一个站点,但我担心其中一个管理员可能会在不知道自己在做什么的情况下关闭它,并破坏该站点。如何以编程方式强制保持漂亮的永久链接?