我们正在尝试为名为Tour Item的主题自定义帖子类型设置新的url结构。我们想在url中重命名,例如“Property” http://gotravel.mikado-themes.com/tour-item/gaudis-city/ 这是网址结构,所以你明白了.. 所以我们希望它是http://gotravel.mikado-themes.com/property/gaudis-city/ - 例如。
我们还想在url结构中添加类别,例如 www.travel.com/greece/santorini/property/name-of-property。
一个小问题是这个主题添加了带插件的自定义帖子类型,我们希望避免因未来的更新而编辑插件。是否有一些功能可以添加以编辑插件添加的自定义帖子类型。 我尝试了几个但不幸的是没有一个工作。
感谢任何帮助。
提前致谢!
答案 0 :(得分:0)
我已经更改了插件自定义帖子类型,如上所述。我也面临同样的问题,但我用这段代码解决了。
add_action('registered_post_type', 'rename_custom_post_type_name', 10, 2);
function rename_custom_post_type_name($post_type, $args) {
global $wp_rewrite;
if ($post_type == 'tour-item') { //your old slug here
$args->rewrite['slug'] = 'property'; //write your new slug here
if ( $args->has_archive ) {
$archive_slug = $args->has_archive === true ? $args->rewrite['slug'] : $args->has_archive;
if ( $args->rewrite['with_front'] )
$archive_slug = substr( $wp_rewrite->front, 1 ) . $archive_slug;
else
$archive_slug = $wp_rewrite->root . $archive_slug;
add_rewrite_rule( "{$archive_slug}/?$", "index.php?post_type=$post_type", 'top' );
if ( $args->rewrite['feeds'] && $wp_rewrite->feeds ) {
$feeds = '(' . trim( implode( '|', $wp_rewrite->feeds ) ) . ')';
add_rewrite_rule( "{$archive_slug}/feed/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
add_rewrite_rule( "{$archive_slug}/$feeds/?$", "index.php?post_type=$post_type" . '&feed=$matches[1]', 'top' );
}
if ( $args->rewrite['pages'] )
add_rewrite_rule( "{$archive_slug}/{$wp_rewrite->pagination_base}/([0-9]{1,})/?$", "index.php?post_type=$post_type" . '&paged=$matches[1]', 'top' );
}
$permastruct_args = $args->rewrite;
$permastruct_args['feed'] = $permastruct_args['feeds'];
add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args );
}
}
因为,您正在尝试更新帖子网址,所以必须在很多地方进行更改。
你的另一个问题是你希望你的类别工作,我现在无法帮助你。
希望这可以帮助您将网址更改为新网址。
由于