Delete attached images from posts

I exported posts from site X to Y. But in every post on site X there was image attached to it (not featured image)<a

I exported posts from site X to Y. But in every post on site X there was image attached to it (not featured image)

<a href="http://x" rel="attachment wp-att-25425"><img src="x/wp-content/uploads/2017/07/x" alt="" width="300" height="141" class="aligncenter size-medium wp-image-25425" /></a>

Is there some way to query all posts on site Y (there are 700 of them) and delete all attachments from posts (i don't need that images)?

I exported posts from site X to Y. But in every post on site X there was image attached to it (not featured image)

<a href="http://x" rel="attachment wp-att-25425"><img src="x/wp-content/uploads/2017/07/x" alt="" width="300" height="141" class="aligncenter size-medium wp-image-25425" /></a>

Is there some way to query all posts on site Y (there are 700 of them) and delete all attachments from posts (i don't need that images)?

Share Improve this question asked Apr 10, 2019 at 13:32 g3arg3ar 331 silver badge4 bronze badges 3
  • In what way are those attachments added to posts? Is it in the content, or as a featured image/gallery images? – djboris Commented Apr 10, 2019 at 13:40
  • If you're not able to edit the files as mentioned by @leymannx in the answer below, you can also use the the WP-CLI search-replace function in combination with a regex to erase the images from site Y's database. If using a regex you need to make sure, the markup is always the same, as you may get unexpected results otherwise. – Fabian Marz Commented Apr 10, 2019 at 14:47
  • those attachments are in content – g3ar Commented Apr 10, 2019 at 20:08
Add a comment  | 

1 Answer 1

Reset to default 0

Having that resulting XML file from the export it's just a matter of editing it precisely to get rid of the images before importing it on the other site.

Taking Sublime Text for example it's pretty easy to find and select all occurrences of [caption and add a line break before them for example. Same for the closing tag. Then find and select all occurrences of [caption again and in the menu under "Selection" select "Expand selection to line". Then hit delete on your keyboard, done.

Maybe you need to separate all occurrences of <![CDATA[[caption (featured images if I'm right) first by replacing them with some custom token to have them excluded by the in-post image search.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745605218a4635638.html

相关推荐

  • Delete attached images from posts

    I exported posts from site X to Y. But in every post on site X there was image attached to it (not featured image)<a

    7小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信