如何通过mysql删除wordpress中没有特色图片的帖子?

强壮的

如何在Wordpress中通过mysql删除没有特色图像的帖子?

我尝试了这段代码,但是它删除了所有包含特色图片的帖子。我只想删除没有特色图片的帖子。

DELETE FROM wp_posts WHERE ID not in (select post_id as p from wp_postmeta where meta_key like "_wp_attached_file")
德马提尼

您遇到的问题是,您正在为各种事情拉回“ post_id”。

您想要的meta_key值是“ _thumbnail_id”,它将父帖子存储在post_id中。

如果要删除,后果自负,可以先尝试执行SELECT而不是DELETE,以确保这样做符合您的实际需求:

DELETE FROM wp_posts WHERE ID not in (select post_id as p from wp_postmeta where meta_key like "_thumbnail_id"); 

更新:这是我的验证测试。

创建了新帖子(7161),然后添加了特征图片。

mysql> select * from wp_postmeta where post_id IN(7161,7162);
+---------+---------+---------------+---------------------+
| meta_id | post_id | meta_key      | meta_value          |
+---------+---------+---------------+---------------------+
|   12533 |    7161 | _edit_lock    | 1512581739:1        |
|   12534 |    7161 | _edit_last    | 1                   |
|   12549 |    7161 | _thumbnail_id | 7115                |
|   12543 |    7161 | CODE1         |                     |
|   12544 |    7161 | _CODE1        | field_57e4293a9238c |
|   12545 |    7161 | CODE3         |                     |
|   12546 |    7161 | _CODE3        | field_57e4297c9238d |
|   12547 |    7161 | CODE2         |                     |
|   12548 |    7161 | _CODE2        | field_57e42ceb508ff |

创建了wp_posts表的副本

create table wp_posts_test like wp_posts;
  Query OK, 0 rows affected (0.01 sec)

并从wp_posts加载实时数据。

insert into wp_posts_test select * from wp_posts;
  Query OK, 6938 rows affected (0.30 sec)

然后运行我的测试查询以删除没有特色图片的所有内容:

delete from wp_posts_test WHERE ID NOT IN (select post_id from wp_postmeta where meta_key="_thumbnail_id"); 
   Query OK, 6937 rows affected (0.37 sec)

检查表,只有一条记录,这是我想保留的帖子:

select * from wp_posts_test \G

*************************** 1. row ***************************
                   ID: 7161
          post_author: 1
            post_date: 2017-12-06 09:29:20
        post_date_gmt: 2017-12-06 17:29:20
         post_content: This is just a test post to see if the featured image OR the post is nuked using a mysql hack.   Standby for destruction. 
           post_title: Feature Image Test Post
        post_category: 0
         post_excerpt: 
          post_status: publish
       comment_status: open
          ping_status: open
        post_password: 
            post_name: feature-image-test-post
              to_ping: 
               pinged: 
        post_modified: 2017-12-06 09:35:18
    post_modified_gmt: 2017-12-06 17:35:18 
post_content_filtered: 
          post_parent: 0
                 guid: http://blog.daviddemartini.com/?p=7161
           menu_order: 0
            post_type: post
       post_mime_type: 
        comment_count: 0

设置1行(0.00秒)

如果您想删除与特色图片没有关联的wp_posts中的所有记录,对我来说似乎很好。为什么它可能对您不起作用,对我来说还是个谜。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从URL中的帖子ID获取WordPress帖子特色图片

如果帖子没有特色图片,则显示更长的摘录(Wordpress)

如何在wordpress博客的单个页面中显示所有帖子的特色图片

没有特色标签的 WordPress 循环帖子

删除没有特色图片的woocommerce产品

在Wordpress中的“帖子页面”上显示特色图片

Wordpress - 以编程方式上传帖子的特色图片

如何在Wordpress中将帖子的特色图片设置为背景图片

如何将 AWS-S3 上传的图片设置为 WordPress 帖子的特色图片?

如何在WordPress中插入设置特色图片?

如何通过mysql在wordpress中获取所有类别的所有帖子?

WordPress特色图片/帖子缩略图未显示

在滑块中显示wordpress特色图片

如何删除所有WordPress帖子中的元值?

从WooCommerce画廊中删除特色图片

WordPress的。仅获取没有精选图片的帖子

如何从循环中排除帖子特色图片?

WordPress特色图片代码

网页的Wordpress特色图片

在一个 sql 查询中检索带有特色图像/缩略图的 Wordpress 帖子

有没有办法验证 Facebook 中的帖子是否已通过 Graph Api 删除?

拉出wordpress帖子中的图片

如何检查Reddit帖子中是否仅包含图片而没有其他内容?

将Feedly特色图片类“ webfeedsFeaturedVisual”添加到Wordpress中的特色图片

使用SQL从WordPress帖子中删除HTML失败而没有错误

Wordpress - 移动帖子后,一些帖子没有显示功能图片

WordPress功能可从具有特定类别的帖子中删除第一张图片

当链接悬停在 WordPress 中时如何显示帖子的图片

RSS提要模板文件中的WordPress特色图片网址