【发布时间】:2022-12-12 02:42:06
【问题描述】:
我有一个关于下载应用程序的网站,当访问者点击下载按钮时
示例:https://deskrush.com/camp-pinewood-2-apk/
参观者将前往 https://deskrush.com/camp-pinewood-2-apk/?target=download&index=0
我希望链接是 https://deskrush.com/camp-pinewood-2-apk/download/0
但我想对所有帖子都这样做
任何人都可以做这个工作吗?
function simple_blog_add_rewrite_rule()
{
$args = [
'numberposts' => -1,
'post_type' => 'post',
'meta_key' => '_wp_page_template',
'meta_value' => 'single-apk.php'
];
$posts = get_posts($args);
if ($posts) {
foreach ($posts as $post) {
add_rewrite_rule(
$post->post_name . '/([^/]+)/?$',
'index.php?name=' . $post->post_name . '&target=$matches[1]',
'top'
);
add_rewrite_rule(
$post->post_name . '/download/([^/]+)/?$',
'index.php?name=' . $post->post_name . '&target=download&index=$matches[1]',
'top'
);
}
}
}
add_action('init', 'simple_blog_add_rewrite_rule');
function simple_blog_add_query_vars_filter($vars)
{
$vars[] = "target";
$vars[] = "index";
return $vars;
}
add_filter('query_vars', 'simple_blog_add_query_vars_filter');
问题是我在发布新帖子时需要刷新重写规则,有什么解决办法吗?
【问题讨论】:
-
请添加一些代码。你试过什么了?您在哪里定义重定向?请附上您的
.htaccess或nginx.conf文件
标签: wordpress custom-wordpress-pages wordpress-rest-api