最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Delete attached images from posts

programmeradmin3浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论