How to merge two or more WordPress posts?
I need to be able to merge two or more posts. What is the exact query (or queries) to make this happen?
The scenario is multiple recommendations that need to be merged into one. I have already sorted out comments merging and meta merging.
Let's say a user recommends Bill Gates, another one Gates Bill and another one makes a typo and adds Bil Gates. I need to merge these three posts and choose the destination one.
UPDATE:
What I need is a complete SQL query for deleting a post and all references to that post. Something like this pseudo-code:
DELETE FROM wp_posts WHERE id = X;
DELETE FROM wp_posts_meta WHERE id = X;
DELETE FROM wp_another_table WHERE id = X;
DELETE FROM wp_yet_another_table WHERE id = X;
where X is the ID of my post.
The code (or plugin) shouldn't auto-detect duplicates. I will present the user a dropdown with a list of posts and the "Delete" option. Before deleting, I will copy the post content from one post to the other using an SQL UPDATE query.
UPDATE 2:
I think I found something, I'll have to check though:
$custom_field_keys = get_post_custom_keys($postid);
foreach($custom_field_keys as $key = $value) {
$valuet = trim($value);
if('_' != $valuet{0} ){
delete_post_meta($postid, $key, '');
}
}
$result = wp_delete_post($postid);