mysql - 手动删除wordpress数据库中的第一张图片

标签 mysql wordpress phpmyadmin

我有 18,000 多个 WordPress 帖子,其中我使用了一个函数来隐藏帖子中的第一张图片,但我不想再这样做了。我想仅使用特色图像,仅此而已,而不必在帖子中插入特色图像只是为了隐藏它(使用该功能)。

我正在考虑手动删除文本编辑器中的所有内容,但不知道要删除哪一个,因为它已经出现了 2 或 3 次。示例:

 INSERT INTO `wp_posts` VALUES(16179, 88, '2009-05-28 08:32:47', '2009-05-28 12:32:47', '<img src="http://localhost/readjunk/wp-content/uploads/2009/05/news_0509_takingbacksundayalbum.jpg" alt="news_0509_takingbacksundayalbum" title="news_0509_takingbacksundayalbum" width="450" height="250" class="alignnone size-full wp-image-16180" />\r\nTaking Back Sunday will be streaming New Again in its entirety on their <a href="http://www.myspace.com/takingbacksunday">MySpace page</a> on Thursday May 28th and Friday May 29th.  New Again officially hits stores next Tuesday, June 2nd.\r\n<!--more-->\r\n\r\nTaking Back Sunday will <a href="http://localhost/readjunk/news/music/blink-182-reunite-and-announce-summer-tour/">be touring on select dates</a> with Blink 182. Check out their music video for Sink Into Me <a href="http://localhost/readjunk/media/music-video-taking-back-sunday-sink-into-me/">here</a>.\r\n\r\nFor more info visit:  <a href="http://www.takingbacksunday.com">www.takingbacksunday.com</a>\r\n', 'MySpace hosting Taking Back Sunday "New Again" listening party tonight and Friday', 0, '', 'publish', 'open', 'open', '', 'myspace-hosting-taking-back-sunday-new-again-listening-party-tonight-and-friday', '', '', '2009-05-28 08:32:47', '2009-05-28 12:32:47', '', 0, 'http://localhost/readjunk/?p=16179', 0, 'post', '', 0, NULL);
INSERT INTO `wp_posts` VALUES(16180, 88, '2009-05-28 08:28:27', '2009-05-28 12:28:27', '', 'news_0509_takingbacksundayalbum', 0, '', 'inherit', 'open', 'open', '', 'news_0509_takingbacksundayalbum', '', '', '2009-05-28 08:28:27', '2009-05-28 12:28:27', '', 16179, 'http://localhost/readjunk/wp-content/uploads/2009/05/news_0509_takingbacksundayalbum.jpg', 0, 'attachment', 'image/jpeg', 0, NULL);
INSERT INTO `wp_posts` VALUES(16181, 88, '2009-05-28 08:32:36', '2009-05-28 12:32:36', '<img src="http://localhost/readjunk/wp-content/uploads/2009/05/news_0509_takingbacksundayalbum.jpg" alt="news_0509_takingbacksundayalbum" title="news_0509_takingbacksundayalbum" width="450" height="250" class="alignnone size-full wp-image-16180" />\nTaking Back Sunday will be streaming New Again in its entirety on their <a href="http://www.myspace.com/takingbacksunday">MySpace page</a> on Thursday May 28th and Friday May 29th.  New Again officially hits stores next Tuesday, June 2nd.\n<!--more-->\n\nTaking Back Sunday will <a href="http://localhost/readjunk/news/music/blink-182-reunite-and-announce-summer-tour/">be touring on select dates</a> with Blink 182. Check out their music video for Sink Into Me <a href="http://localhost/readjunk/media/music-video-taking-back-sunday-sink-into-me/">here</a>.\n\nFor more info visit:  <a href="http://www.takingbacksunday.com">www.takingbacksunday.com</a>\n', 'MySpace hosting Taking Back Sunday "New Again" listening party tonight and Friday', 0, '', 'inherit', 'open', 'open', '', '16179-revision', '', '', '2009-05-28 08:32:36', '2009-05-28 12:32:36', '', 16179, 'http://localhost/readjunk/uncategorized/16179-revision/', 0, 'revision', '', 0, NULL);

只是两个 img 标签还是只是第一行?

最佳答案

在您的问题中,您发布了 3 个不同的 INSERT 语句来代表初始帖子(post_status 为“publish”),下一行是上传到媒体库的图像(带有attachmentpost_type),第三个表示对初始帖子的编辑(post_status 为“inherit”)

我建议以编程方式执行此操作,而不是使用文本编辑器。您可以循环浏览所有帖子并使用 WordPress API 创建新的编辑,也可以仅使用新的 post_content 更新最新的帖子。

您应该能够使用正则表达式删除内容中的第一张图像。像这样的东西:

$post->post_content = preg_replace( "~^[^>]*>~", "", $post->content );

查看 Regex101.com 上的正则表达式描述:https://regex101.com/r/jP9vZ6/1

关于mysql - 手动删除wordpress数据库中的第一张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32460133/

相关文章:

mysql - mysql 中的总和作为一列

php - 发送短信以获取特定电子邮件通知和订单状态

wordpress - 如何删除 WordPress 网站上的 bitnami 横幅?

php - 基于付款方式的 WooCommerce 订单接收重定向

phpmyadmin 错误 : cant create table error number 150

c# - 向数据库提交数据时不显示消息框

mysql - 对两个表使用 ON DUPLICATE KEY UPDATE

android - 通过 Android 3g 连接到服务器并从 phpmyadmin 检索数据

mysql - 无法登录 MySQL 服务器 (PhpMyAdmin)

mysql - 将行插入 MySQL 数据库