0

我需要在 Wp 数据库(帖子内)上为特定时间段内的 100 多个帖子中的给定关键字编写锚文本链接(发布于 2013 年 1 月 16 日至 2013 年 5 月 23 日之间的帖子)。

我考虑过使用插件,但除了日期范围不可能之外,一旦插件被禁用,所有链接都必须保留在帖子上......

我也想过使用 sql 查询,但它会在图像上写入链接,并且 O 不知道如何在其上设置时间范围

 UPDATE wp_posts SET post_content = REPLACE ( post_content, 'my keyword', '<a href="#">my keyword</a>' );

有没有简单的方法可以做到这一点,或者我必须手动做到这一点?

4

3 回答 3

0
UPDATE wp_posts SET post_content = REPLACE ( post_content, 'my keyword', '<a href="#">my keyword</a>' ) WHERE <insert date field> >= 2013-01-16 AND <insert date field> <= '2013-05-23';
于 2013-05-23T15:56:14.967 回答
0

好吧,这不是解决这个问题的方法,但无论如何!

如果您担心链接被破坏,那么在运行更新关键字查询之前,只需运行其他几个查询,例如

UPDATE wp_posts SET post_content = REPLACE ( post_content, 'title="my keyword"', 'title="Xmy keywordX"'

UPDATE wp_posts SET post_content = REPLACE ( post_content, 'alt="my keyword"', 'alt="Xmy keywordX"'

这样链接就不会被搞砸了。

然后运行您的更新查询

UPDATE wp_posts SET post_content = REPLACE ( post_content, 'my keyword', '<a href="#">my keyword</a>' )

然后设置标题和 alt 回来。

UPDATE wp_posts SET post_content = REPLACE ( post_content, 'title="Xmy keywordX"', 'title="my keyword"'

UPDATE wp_posts SET post_content = REPLACE ( post_content, 'alt="Xmy keywordX"', 'alt="my keyword"'

正如我所说,这不是最好的方法。

我会查询所有记录,然后循环遍历它们,并以与 Steven 发布的链接类似的方式用正则表达式替换我想要的东西。

于 2013-05-23T16:13:11.007 回答
0

您可以使用 post_date_gmt 或 post_date 字段。以下示例使用的是 gmt 日期

UPDATE wp_posts SET post_content = REPLACE ( post_content, 'my keyword', '<a href="#">my keyword</a>' ) WHERE post_date_gmt >= '2013-01-16 00:00:00' and post_date_gmt <= '2013-05-23 23:59:59'

防止编辑图像标题更复杂。我想我会为时间空间中的所有内容字段做一个 foreach 并使用正则表达式来找出要替换的内容。

我发现了另一个关于这个问题的帖子:http: //www.marcogoncalves.com/2011/03/php-regexp-replace-words-in-html-string-if-not-inside-tags/

于 2013-05-23T15:58:39.647 回答