开发者

Delete wordpress posts with 0 views [wp_postviews plugin]

开发者 https://www.devze.com 2023-02-25 06:46 出处:网络
This开发者_运维技巧 select works perfect in my opinion... any suggestion?? SELECT * FROM`wp_posts` ,`wp_postmeta`

This开发者_运维技巧 select works perfect in my opinion... any suggestion??

SELECT * 
FROM  `wp_posts` ,  `wp_postmeta` 
WHERE  `post_type` =  'post'
AND post_id = ID
AND DATEDIFF( NOW( ) ,  `post_date` ) >400
AND meta_key =  "views"
AND meta_value =0;

the problem is that I don't know how I can I do a DELETE to remove all this posts! Any helps? Thanks


[edit, after comments - not tested, so possibly not 100% correct]

create table post_ids_to_remove (postid bigint);

insert into post_ids_to_remove (postid) values (
  SELECT post_id
      FROM  `wp_posts` ,  `wp_postmeta` 
      WHERE  `post_type` =  'post'
      AND post_id = ID
      AND DATEDIFF( NOW( ) ,  `post_date` ) >400
      AND meta_key =  "views"
      AND meta_value =0
)

delete from `wp_postmeta` where post_id in(
      SELECT postid
      FROM  `post_ids_to_remove`
);

delete from `wp_posts` where id in(
      SELECT postid
      FROM  `post_ids_to_remove`
);

drop table post_ids_to_remove;


 INSERT into post_ids_to_remove (postid)

 SELECT ID FROM  wp_posts ,  wp_postmeta WHERE wp_posts.post_type = 'post' AND wp_postmeta.post_id = ID AND wp_postmeta.meta_key = 'views' AND wp_postmeta.meta_value = 0;

 DELETE from `wp_postmeta` where post_id in(
          SELECT postid
          FROM  `post_ids_to_remove`
    );

 DELETE from `wp_posts` where id in(
          SELECT postid
          FROM  `post_ids_to_remove`
    );

 DROP table post_ids_to_remove;
0

精彩评论

暂无评论...
验证码 换一张
取 消