如何从数据库中删除所有外部链接
我有一个包含数百篇帖子的 WordPress 网站,我需要删除此帖子中的所有外部链接。但新帖子也应该有外部链接。这就是为什么我必须从数据库中删除外部链接而不是使用脚本的原因。
有什么想法如何做到这一点吗?
编辑,我做了这个脚本,删除了 ID 为 1 - 3568 的帖子中的链接
add_filter( 'the_content', 'filter_the_content_in_the_main_loop' );
function filter_the_content_in_the_main_loop( $content ) {
if ( is_single(range(1, 3568)) ) {
$content = preg_replace(array('"<a href(.*?)>"', '"</a>"'), array('',''), $content);
}
return $content;
}
,是否可以添加一些东西,什么会将这些数据发送到数据库?
i have WordPress website with hundreads posts and i need remove all external links from this posts. But also new posts should have external links. So thats reason why i have to remove external links from database and not with script.
Any ideas how to do that?
Edit, i did this script what remove links from posts with ID 1 - 3568
add_filter( 'the_content', 'filter_the_content_in_the_main_loop' );
function filter_the_content_in_the_main_loop( $content ) {
if ( is_single(range(1, 3568)) ) {
$content = preg_replace(array('"<a href(.*?)>"', '"</a>"'), array('',''), $content);
}
return $content;
}
Is possible add there something, what will send this data to database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先需要识别保存链接的表和列。
有两种类型的链接:
站点链接
和外部链接
。站点链接应类似于
http:\\example.com\anything_else
WP的post标准表是
wp_posts
,但是hiperlinks则取决于自定义(可以是wp_post中的一列,也可以是其他地方。这里由你来查找)假设表是
wp_posts
并且列是links
那么您需要按模式查找并更新这些列。主要模式应该是
以:http:\\example.com
开头(意味着将保留为站点链接而不是外部链接)翻译为sql
注意:WP标准DB是MySql
更新:
First need to identify the table and the column which hold the links.
There are 2 types of links :
site links
andexternal links
.Site links should be something like
http:\\example.com\anything_else
WP standard table for post is
wp_posts
, but for hiperlinks depends on the customization (can be a column in wp_post or maybe elsewhere. Here is up to u to find)Assume the table is
wp_posts
and the column islinks
then you need to find by pattern and update with nothing those columns.Mainly the pattern should be
start with : http:\\example.com
(means links that will be keep as site links and not external)Translated to sql
Note: WP standard DB is MySql
Update: