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)?

  • In what way are those attachments added to posts? Is it in the content, or as a featured image/gallery images? – dboris Apr 10 '19 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 Apr 10 '19 at 14:47
  • those attachments are in content – g3ar Apr 10 '19 at 20:08
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.

|improve this answer|||||
  • is it possible to give me example (honestly i dont know how to do it )<content:encoded> <![CDATA[[:hr]<a href="http:/url" rel="attachment wp-att-29100"><img src="http:/url" alt="" width="300" height="200" class="aligncenter size-medium wp-image-29100" /></a> post text[:]]]> </content:encoded> ignore {:hr} tags, those are for qtranslate, p.s. they are not featured images, they are simply images inserted into post – g3ar Apr 10 '19 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.