是否可以使用变量从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
如果您有任何建议,我们将不胜感激!
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 );