使用查询从wordpress中的帖子中删除链接 [英] Removing links from posts in wordpress using query

查看:123
本文介绍了使用查询从wordpress中的帖子中删除链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对mysql不是很好,所以我需要一些帮助。

I am not very good with mysql so i need some help.

我试图从我的wordpress博客中删除一些特定的链接。我有很多外向链接到几个域,我想删除其中一个链接。例如,所有链接通往dontneedlink.com或以dontneedlink.com/(某些子页面)开头

I am trying to remove some specific links from my wordpress blog. I have a lot of outgoing links to several domains and i want to remove just links to one of them. For example all links that lead to dontneedlink.com or start with dontneedlink.com/(some child page)

我已经尝试了

UPDATE wp_posts SET post_content = REPLACE (
post_content,
'Item to replace here',
Replacement text here');

但这不是我的上帝因为我有很多关键词而且有很多关键词组合。

But this is not god for me because I have a lot of key words and there is a lot of combinations.

所以我需要某种查询来识别包含dontneedlink.com的链接,并删除href文本并保持关键字保持不变。

So I need some kind of query to recognize my links that include dontneedlink.com and to remove href text and leave keyword untouched.

<  a href="http:// dontneedlink.com">Test</a> -> Test 

<  a href="http:// dontneedlink.com">Test Again</a> -> Test Again

<  a href="http:// dontneedlink.com/childpage">Test Again 2</a> -> Test Again 2

这有可能吗?
这样可以省去很多时间,而不是从一个帖子转到另一个帖子并手动删除。

Is this possible at all? This would save me a lot of time instead to go from one to another post and remove manually.

推荐答案

你需要使用'like'来查找帖子和子字符串索引以删除不需要的内容

you need to use 'like' to find the posts and substring index to remove the unwanted content

substring_index(substring_index(table.column,'href = ',-1),'',1)将提取您的链接

mysql> SELECT REPLACE(table_column, substring_index( substring_index(table.column, 'href="', -1),  '"',1) , '');

这将为您提供没有链接的文本。您将离开

this will give you the text without the link. You will be left with

<  a href="">Test</a>

然后执行另一个替换或子串索引以删除任何不需要的遗骸。

then do another replace or substring index to remove any undesired remains.

最后使用右边的过滤器运行它:

finally run it with the right filter in where:

UPDATE wp_posts SET post_content = REPLACE (
post_content,
'Item to replace here',
Replacement text here')
where mycolumn like "%dontneedthisdomain.com%"

这篇关于使用查询从wordpress中的帖子中删除链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆