我寫了這個快速腳本,它在移動wordpress博客的位置時更新數據庫。問題: 如果它顯示已更新了多少行,那將是一件好事。這可能嗎?使用表格的Wordpress更新數據庫
<?php
if(isset($_GET['confirm'])){
// Load Wordpress
require_once('wp-load.php');
// Form variables
$site_was = $_GET['site_was'];
$site_now = $_GET['site_now'];
$db_queries = array(
"UPDATE wp_options SET option_value = replace(option_value, '".$site_was."', '".$site_now."') WHERE option_name = 'home' OR option_name = 'siteurl'",
"UPDATE wp_posts SET guid = REPLACE (guid, '".$site_was."', '".$site_now."')",
"UPDATE wp_posts SET post_content = REPLACE (post_content, '".$site_was."', '".$site_now."')",
"UPDATE wp_posts SET post_content = REPLACE (post_content, 'src=\"".$site_was."', 'src=\"".$site_now."')",
"UPDATE wp_posts SET guid = REPLACE (guid, '".$site_was."', '".$site_now."') WHERE post_type = 'attachment'",
"UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, '".$site_was."','".$site_now."')"
);
foreach ($db_queries as $sql) {
$wpdb->query($sql);
}
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<p>E.g http://examples.com or http://www.example.com/shop</p>
<label>
Site was:
<input type="text" name="site_was" value="<?php if(isset($_GET['site_was'])) echo $_GET['site_was']?>" size="50" />
</label>
<br />
<label>
Site now:
<input type="text" name="site_now" value="<?php if(isset($_GET['site_now'])) echo $_GET['site_now']?>" size="50" />
</label>
<input type="submit" name="confirm" value="Update Datebase" />
</form>
<?php } ?>
我沒有答案,但我看你是使用完整的表名。最好使用$ wpdb-> prefix.'options'而不是'wp_options',如果您更改了表前綴,您將不必調整查詢 – janw 2012-01-10 04:46:57