变量是否可用于重写自定义发布类型固定链接?

时间:2014-02-06 作者:Tai Sem

是否可以使用变量从wp\\u terms->slug重写自定义Post类型permalink?

WPDB: wp\\U术语->slug=健康生活

A1) Current Custom Post Type args:

\'rewrite\' => array( \'slug\' => \'issues/resources\' ),

A2) Current Permalink (works great!):

http://localhost/issues/resources/title-of-resource.html

B1) Desired Custom Post Type args (is this possible?):

\'rewrite\' => array( \'slug\' => \'issues/$WP_TERM_SLUG_VAR/resources\' ),
B2) Desired Permalink:

http://localhost/issues/healthy-living/resources/title-of-resource.html
如果您有任何建议,我们将不胜感激!

1 个回复
SO网友:Salem Terrano

过滤“pre\\u post\\u link”以更改永久链接规则,第一个属性是为管理员设置的规则,第二个属性是要形成链接的元素

function my_pre_post_link( $permalink, $post, $leavename ) {
  // filtered by post_type, returns the format permalink
  if( $post->post_type != \'book\' ) return \'/bookis_custom/%postname%\';
  return $permalink;
}

add_filter( \'pre_post_link\', \'my_pre_post_link\', 9, 3 );

结束

相关推荐

Advanced permalinks structure

我想得到这个:mysite.com/category/tag/ 示例:mysite.com/news/sports/ 新闻是一个类别,体育是一个标签我该怎么做?谢谢