$dbname = DB_NAME;
$servername = DB_HOST ;
$username = DB_USER ;
$password = DB_PASSWORD ;
try {
$conn = new PDO(“mysql:host=$servername; dbname=$dbname”, $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ ERRMODE, PDO::ERRMODE_EXCEPTION);
echo “Connected successfully”;
$sql=”SELECT post_content,ID FROM wp_posts WHERE post_type=’resources’ AND post_status=’publish'”;
$page=$conn->prepare($sql);
$page->execute();
$row = $page->fetchAll(PDO::FETCH_ ASSOC);
foreach($row as $values)
{
$post_content=clean(strip_tags($values['post_content'])) ;
$id=$values[‘ID’];
if(($id>0)&&($post_content!=” ))
{
$sql1=”UPDATE wp_posts SET post_content='”.$post_content. “‘ WHERE post_type=’resources’ AND post_status=’publish’ AND ID='”.$id.”‘”;
$page=$conn->prepare($sql1);
$page->execute();
}
}
}
catch(PDOException $e)
{
echo “Connection failed: ” . $e->getMessage();
}
function clean($string) {
//$string = str_replace(‘ ‘, ‘-‘, $string); // Replaces all spaces with hyphens.
return preg_replace(‘/[^A-Za-z0-9 \-]/’, ”, $string); // Removes special chars.
}