【问题标题】:Query mysql Replace in Wordpress在 Wordpress 中查询 mysql 替换
【发布时间】:2020-03-14 17:26:31
【问题描述】:

我需要对 WordPress (+30.000) 中的所有帖子运行查询

从 * 中删除所有内容 只要:

我正在阅读以下可能性:

UPDATE wp_posts
  SET post_content = 
  REPLACE( post_content, '</iframe>&', '</iframe>' );


SELECT SUBSTRING_INDEX('', '</iframe>', 1) as result;

但不工作。

非常感谢您的帮助。

【问题讨论】:

    标签: mysql wordpress


    【解决方案1】:

    似乎没有通配符,因此我调整了此处找到的解决方案: MySQL for replace with wildcard

    只有在每个帖子的内容中只有 1 个时才有效。因为它会占用内容直到并包括该内容。

    UPDATE wp_posts
    SET post_content = SUBSTR(post_content, 1, LOCATE('</iframe>', post_content)+8)
    

    请注意,+8 是该字符串的长度减 1:&lt;/iframe&gt;。您可能想先在 1 行上对其进行测试。

    我刚刚意识到这应该只应用于其中包含&lt;/iframe&gt; 的行,否则没有它的行将变为空。 所以你需要它:

    UPDATE wp_posts
    SET post_content = SUBSTR(post_content, 1, LOCATE('</iframe>', post_content)+8) WHERE id IN (SELECT id FROM wp_posts WHERE post_content LIKE '%</iframe>%');
    

    【讨论】:

    • 对不起,我觉得我表达得不好(我对mysql也很陌生)。我必须从字符串 中删除 WP 的所有帖子的所有内容我想在我的第一条消息中放入的内容是将 * (在 之后的所有内容)仅替换为
    • 效果很好。 UPDATE wp_posts SET post_content = SUBSTR(post_content, 1, LOCATE('', post_content)+8) 非常感谢!
    • 您是否仔细检查过其中没有 iframe 的帖子/页面没有变空?如果没有,没问题!
    猜你喜欢
    • 2015-12-06
    • 2011-07-24
    • 1970-01-01
    • 2013-02-12
    • 2015-10-21
    • 1970-01-01
    • 2022-08-04
    • 2011-03-24
    • 1970-01-01
    相关资源
    最近更新 更多