有没有办法在每个URL的末尾为帖子批量添加一个单词?我有大约3500个帖子,添加到每个帖子上会很耗时。
例如,URL是
www.example.com/my-post/
www.examle.com/new-post/
我想在URL的末尾添加一个单词www.example.com/my-post-word/
www.examle.com/new-post-word/
有MySql脚本来做这样的事情吗?有没有办法在每个URL的末尾为帖子批量添加一个单词?我有大约3500个帖子,添加到每个帖子上会很耗时。
例如,URL是
www.example.com/my-post/
www.examle.com/new-post/
我想在URL的末尾添加一个单词www.example.com/my-post-word/
www.examle.com/new-post-word/
有MySql脚本来做这样的事情吗?以下是您的代码:
if ( isset($_GET[\'slug-update\']) ) {
$posts = get_posts();
foreach($posts as $singlepost) {
if($singlepost->post_status === \'publish\'){
$post_id = $singlepost->ID;
$current_slug = $singlepost->post_name;
$updated_slug = $current_slug . \'-word\';
}
wp_update_post( array(
\'ID\' => $post_id,
\'post_name\' => $updated_slug ) );
}
die(\'Slug Updated\');
}
将此添加到主题的功能中。php。然后使用www.example.com/?slug-update
P、 这将只更新默认的post类型“post”(备份数据库以确保安全)
如果这有帮助,请告诉我。
你不能把它添加到WP admin中吗permalink settings?
在某些情况下,当给出错误的查询时,将尝试运行该查询,并给出警告(而不是错误)。在MySQL提示符中,要查看这些警告,可以运行SHOW WARNINGS;.例如:mysql> SELECT * FROM wp_posts WHERE id = \"hello\"; Empty set, 1 warning (0.00 sec) mysql> SHOW WARNINGS; +---------+------+----------------------------