没有为特定于帖子类型的帖子格式生成重写规则。如果您想为特定于post类型的post格式创建漂亮的URL,您需要add them yourself.
// post_type doesn\'t seem to work,
// add rules to set custom query var
function resource_post_formats_urls() {
add_rewrite_rule(
\'resource/type/([^/]+)/?\',
\'index.php?post_format=$matches[1]&resource_only=1\',
\'top\'
);
// pagination
add_rewrite_rule(
\'resource/type/([^/]+)/page/([0-9]+)/?\',
\'index.php?post_format=$matches[1]&paged=$matches[2]&resource_only=1\',
\'top\'
);
}
add_action( \'init\', \'resource_post_formats_urls\' );
// add query var so it\'s recognized
function resource_query_vars( $qvars ) {
$qvars[] = \'resource_only\';
return $qvars;
}
add_filter( \'query_vars\', \'resource_query_vars\' , 10, 1 );
// check if query var is set and modify post_type for the query
function modify_resource_tax_query( $query ) {
if( isset( $query->query_vars[\'resource_only\'] ) ){
$query->set( \'post_type\', array(\'resource\') );
}
}
add_action( \'pre_get_posts\', \'modify_resource_tax_query\' );
请注意,这将只处理现有格式的传入请求。您需要手动创建指向这些页面的链接。
另一种处理方法是创建自己的自定义格式分类法,并设置rewrite
slug
到resource/type
.