Mass replace of TITLE in WordPress

The task:
There is the site at WP, which consists of many pages, not the posts but the pages. The half od these pages has wrong title, (” – the title of the website”).

We need to replace all “-” with the titles of the pages.

 

Solution:
$work_dir="./";
// working directory- should certainly end with
// symbol "/"

$excl_dir=array();
$excl_dir[0]=”./no_work_here/”;
$excl_dir[1]=”./and_here/and_here/”;

// directories where are no search/change- should end with
// symbol”/”

$file_mask_1=”.html”;
$file_mask_2=”.php”;
// masks of processing files (all files which have this line in the title,
// will be processed)

$search_str=”False Title”; #what search for
$replace_str=”Tru Title”; #what replace with

//************************************************** ****

$level=0;

function sr($dir)
{
global $level,$file_mask_1,$file_mask_2,$search_str,$replace_str,$excl_dir;
echo ““;
for ($i=0;$i echo $dir.”
“;

if (@in_array($dir,$excl_dir))
{
echo ” – needn’t search & replace
“;
return;
}

echo ”
“;

$p = dir($dir);
while($ent=$p->read())
{
if ($ent!=”.” && $ent!=”..” && !is_dir($dir . $ent) && (eregi(sql_regcase($file_mask_1),$ent) || eregi(sql_regcase($file_mask_2),$ent)))
{
$tmp=@file($dir.$ent);
$str=@implode(“”,$tmp);

if (strpos(“@!#%xrenoder^&*()”.$str,$search_str))
{
for ($i=0;$i echo $dir.$ent.” found…”;

$str=str_replace($search_str,$replace_str,$str);

if ($fp=@fopen($dir.$ent, “w”))
{
flock($fp,LOCK_EX);
fwrite($fp,$str);
fclose($fp);
echo ” and replace
“;
}
else echo ” and can’t replace
“;
}

}
elseif($ent!=”.” and $ent!=”..” and is_dir($dir . $ent))
{
$level++;
sr($dir.$ent.”/”);
$level–;
}
}
$p->close();

return;
}

sr($work_dir);

echo “SEARCH & REPLACE Complete”;

?>

RSS

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>