我有一个名为“专家”的CPT,它是在我买的一个主题中创建的,我不知道在哪里也不知道在哪里更改它。我需要将一个参数更改为“with\\u front”=>false,因为我的通用排列结构与/blog匹配,我不希望专家出现在/blog/experts中。有没有办法在函数文件中添加一些内容?我试过这个(How to set "with_front'=>false" to a plugin-generated cpt?) 还有各种各样的事情,但都没能成功。谢谢:)
如何从现有的自定义帖子类型更改‘WITH_FORWARE’键?
3 个回复
最合适的回答,由SO网友:birgire 整理而成
你可以试试新的register_post_type_args
过滤器进行调整。
以下是一个未经测试的示例:
/**
* Set \'with_front\' to false for the \'experts\' post type.
*/
add_filter( \'register_post_type_args\', function( $args, $post_type )
{
if( \'teachers\' === $post_type && is_array( $args ) )
$args[\'rewrite\'][\'with_front\'] = false;
return $args;
}, 99, 2 );
Updated 来自@Agnes的新信息:帖子类型为teachers
不experts
.SO网友:connectjax
此外,如果CPT有相关的分类法,我也成功地使用以下代码重写了这些分类法:
/**
* Set \'with_front\' to false for the \'portfolio_category\' post taxonomy.
*/
add_filter( \'register_taxonomy_args\', function( $args, $taxonomy )
{
if( \'portfolio_category\' === $taxonomy && is_array( $args ) )
$args[\'rewrite\'][\'with_front\'] = false;
return $args;
}, 99, 2 );
以防对任何人都有帮助。SO网友:Agnes
此解决方案有效,添加到父主题函数中。php:
add_filter( \'register_post_type_args\', function( $args, $post_type )
{
$args[\'rewrite\'][\'with_front\'] = false;
return $args;
}, 10, 2 );