loganivan
Forum Replies Created
-
Updated againd:
<?php function get_post_id_by_meta_key_and_value($value) { global $wpdb; $meta = $wpdb->get_results("SELECT * FROM <code>".$wpdb->postmeta."</code> WHERE meta_value = ('".$value."')"); if (is_array($meta) && !empty($meta) && isset($meta[0])) { $meta = $meta[0]; } if (is_object($meta)) { return $meta->post_id; } else { return false; } } if (($_POST['key']=='delete')&&($_POST['postid_array']!='')){ $del_list=explode(",",$_POST['postid_array']); foreach ($del_list as $postid) { $title=get_the_title( $postid ); $delete = wp_delete_post($postid, true); //True force deletes the post and doesn't send it to the Trash if($delete) echo "<div id=\"message\" class=\"updated fade\"><p>Post $title deleted successfully!</p></div>\n"; else echo "<div id=\"message\" class=\"updated fade\"><p>Post $title was not deleted!</p></div>\n"; } } echo 'This tool will check for duplicate posts in your wordpress site and remove them.<br>'; if ($_POST['key']=='check'){ set_time_limit(0); $array=get_unique_post_meta_values('mypostID', 'post'); function get_duplicates( $array ) { return array_unique( array_diff_assoc( $array, array_unique( $array ) ) ); } $value = get_duplicates( $array ); $results[] = $value; echo "<br>" ; if (count($results)<>0){ $i=0; echo "There are ".count($results)." Duplicate post(s) in your wordpress site.<br>"; foreach ($results as $result) { $i++; $postid= get_post_id_by_meta_key_and_value($result); $postid_array.=$postid.","; echo "$i. <a href=".post_permalink( $postid )." target='_blank'>".get_the_title( $postid )."</a>"; echo "<br>" ; } $postid_array=rtrim($postid_array,","); echo'<br><form name="delvid" method="post" action=""><input name="key" value="delete" type="hidden" /><input name="postid_array" value="'.$postid_array.'" type="hidden" /><input type="submit" value="Delete all Duplicate Posts" id="Submit" class="button-primary"/></form>'; } else {echo "Cool! All Posts are uniques!";} }else{ echo'<br><form name="delvid" method="post" action=""><input name="key" value="check" type="hidden" /><input type="submit" value="Check" id="Submit" class="button-primary"/></form>'; } ?>
Everything seems right, but I do not know why the duplicate posts list is not presented to me? I only get a string as output!:
This tool will check for duplicate posts in your wordpress site and remove them.
There are 1 Duplicate post(s) in your wordpress site.
1. //(only: 1.)I have updated the code:
<?php function get_post_id_by_meta_key_and_value($value) { global $wpdb; $meta = $wpdb->get_results("SELECT * FROM <code>".$wpdb->postmeta."</code> WHERE meta_value = ('".$value."')"); if (is_array($meta) && !empty($meta) && isset($meta[0])) { $meta = $meta[0]; } if (is_object($meta)) { return $meta->post_id; } else { return false; } } if (($_POST['key']=='delete')&&($_POST['postid_array']!='')){ $del_list=explode(",",$_POST['postid_array']); foreach ($del_list as $postid) { $title=get_the_title( $postid ); $delete = wp_delete_post($postid, true); //True force deletes the post and doesn't send it to the Trash if($delete) echo "<div id=\"message\" class=\"updated fade\"><p>Post $title deleted successfully!</p></div>\n"; else echo "<div id=\"message\" class=\"updated fade\"><p>Post $title was not deleted!</p></div>\n"; } } echo 'This tool will check for duplicate posts in your wordpress site and remove them.<br>'; if ($_POST['key']=='check'){ set_time_limit(0); $array1=get_unique_post_meta_values('mypostID', 'post'); //$value = array(); // $dupl = array_unique( array_diff_assoc( $array, array_unique( $array ) ) ); //if (($key = array_search($array, $dupl, TRUE))) { if ($dupl = array_unique(array_diff_assoc($array1, array_unique($array1)))){ $results[] = $dupl; } // } echo "<br>" ; if (count($results)<>0){ $i=0; echo "There are ".count($results)." Duplicate post(s) in your wordpress site.<br>"; foreach ($results as $result) { $i++; $postid= get_post_id_by_meta_key_and_value($result); $postid_array.=$postid.","; echo "$i. <a href=".post_permalink( $postid )." target='_blank'>".get_the_title( $postid )."</a>"; echo "<br>" ; } $postid_array=rtrim($postid_array,","); echo'<br><form name="delvid" method="post" action=""><input name="key" value="delete" type="hidden" /><input name="postid_array" value="'.$postid_array.'" type="hidden" /><input type="submit" value="Delete all Duplicate Posts" id="Submit" class="button-primary"/></form>'; } else {echo "Cool! All Posts are uniques!";} }else{ echo'<br><form name="delvid" method="post" action=""><input name="key" value="check" type="hidden" /><input type="submit" value="Check" id="Submit" class="button-primary"/></form>'; } ?>
was better read now.
Hey Friend @Soumanta_Bhowmick , thank you so much!! Worked Very well!! Great!!
Thank you very much, had a plugin that did not work well when I needed to delete images out of wordpress, through the linux terminal, in case of emergency to free more disk space, and the posts were left without images in featured images, but in [box festured image] in post edit, said that I still had a picture!it was empty background, and with the name of the image that I deleted out of wordpress !! wordpress continued with featured images applied in post edit! there was an empty bottom! very strange! but the thumbnails in the posts, disappeared, so, as the wordpress system understood that I still had a featured image, my code did not work, but its works because it works with the thumbs! … thank you very much friends ?? ..
I liked to know this site that you indicated, I am creating a new blog and I will create a post indicating it! … I have only one doubt ?! because your code does not work with nginx! it drops the site the moment we activate the plugin! In apache everything happens ok … it was just a doubt .. not important .. your code already serves me very well and thank you very much ??