Site icon Hip-Hop Website Design and Development

How to merge the content of posts that have the same title?

Good evening everyone… I apologize in advance for my bad English, for any complaints go to google translate :).

I need to merge posts with the same title and I don’t know how to do it. The situation is as follows… I have many posts with exactly the same title as other posts but different content. Joining them manually would take a lot of time; I would like to be able to do it automatically via a php snippet.

I add a few examples :

title:"I love you Madrid" with content:"content madrid 1" ; title:"I love you Madrid" with content:"content madrid 2" ; (there may also be title:"I love you Madrid" with content:"content madrid 3", etc).

title:"I love you London" with content:"content london 1" ; title:"I love you London" with content:"content london 2" ; (there may also be title:"I love you London" with content:"content london 3", etc).

title:"I love you Rome" with content:"content rome 1" ; title:"I love you Rome" with content:"content rome 2" ; (there may also be title:"I love you Rome" with content:"content rome 3", etc).

The final result should be :

title:"I love you Madrid" with content:"content madrid 1 + content madrid 2 + content madrid 3 + etc"

title:"I love you London" with content:"content london 1 + content london 2 + content london 3 + etc"

title:"I love you Rome" with content:"content rome 1 + content rome 2 + content rome 3 + etc"

Unfortunately I’m not a php specialist, otherwise I wouldn’t be bothering you :). The code should work in this way, however it could be wrong:

1 – search the database for posts that have the same title (maybe using get_posts or query_posts)

2 – extract the content from these posts

3 – create a new post containing this content

4 – delete the starting posts