### [wordpress 内容备份镜像站点建立方法及注意事项](https://www.prosaas.cn/article/9746) **Published:** 2019-09-26T01:43:11 **Author:** 5201314 **Excerpt:** 下面由WordPress教程栏目给大家介绍wordpress内容备份镜像站点建立方法及注意事项,希望对需要的朋… 下面由**WordPress教程**栏目给大家介绍wordpress内容备份镜像站点建立方法及注意事项,希望对需要的朋友有所帮助! ![](//zhiqipro.oss-cn-beijing.aliyuncs.com/2023/12/20231212132721946.jpg) 作为虾米级站长一枚,实则是不懂代码的菜鸟,由于自己的站点是小水管主机,而且稳定性也难以保障,在很多访客的建议下,也想建立一个内容镜像站点,以实现当主站的主机维护时,能够有一个备用站点让访客访问。 最先我是想能够有一个共用的数据库可以给两个站点一起使用,但百度查了资料后,发现这对于虚拟主机建站来说好像不适用。 直到找到了以下的代码,可以实现源站发表文章时,自动在镜像站点也发表出来。 第一步,在镜像站根目录创建一个命名为 post.php 的 php 文件,代码内容: //以下为代码正文… $\_POST\['title'\], 'post\_content' => $\_POST\['content'\], 'post\_status' => 'publish', 'post\_author' => 1, //发布文章的作者 ID,1 为管理员 'post\_date' => $\_POST\['date'\], 'tags\_input' => $\_POST\['tags'\], 'post\_category' => $category, 'post\_type' => $\_POST\['type'\] ); wp\_insert\_post( $info ); } 第二步,在主站主题的 functions.php 文件的最后一个?>前加入已下代码,并设置 key,修改 API 地址。 //文章推送 add\_action('publish\_post', 'fanly\_sync\_post'); //钩子,在文章发布时执行 function fanly\_sync\_post($post\_ID) { $key='123456'; //输入你设置的密钥 $url='http://3838521.com/post.php';//API地址,就是接受数据的那个站点,修改为自己站点 $post\_info = get\_post($post\_ID); if ( $post\_info->post\_status == 'publish' && $\_POST\['original\_post\_status'\] != 'publish' ) { $title=$\_POST\['post\_title'\]; $content=$\_POST\['content'\]; $date=$\_POST\['aa'\].'-'.$\_POST\['mm'\].'-'.$\_POST\['jj'\].' '.$\_POST\['hh'\].':'.$\_POST\['mn'\].':'.$\_POST\['ss'\]; $category=''; for($x=1;$xpost\_status == 'publish' && $\_POST\['original\_post\_status'\] != 'publish' ) { $title=$\_POST\['post\_title'\]; $content=$\_POST\['content'\]; $date=$\_POST\['aa'\].'-'.$\_POST\['mm'\].'-'.$\_POST\['jj'\].' '.$\_POST\['hh'\].':'.$\_POST\['mn'\].':'.$\_POST\['ss'\]; $category=''; for($x=1;$x '替换为这些' '\\"20\\"\]' => '"20"\]', '\\"10\\"\]' => '"10"\]', '\\"50\\"\]' => '"50"\]' ); $text = str\_replace(array\_keys($replace), $replace, $text); return $text; } add\_filter('the\_content', 'wpdaxue\_replace\_text'); //正文 add\_filter('the\_excerpt', 'wpdaxue\_replace\_text'); //摘要 add\_filter('comment\_text', 'wpdaxue\_replace\_text'); //评论 ?> 在此文中,使用到的代码都是万能的博主们提供的,我只是对其进行了一个有效的整合,来实现我的需求,在此感谢共享精神的博主们的辛勤付出! 以上就是wordpress 内容备份镜像站点建立方法及注意事项的详细内容,更多请关注知企PROSAAS其它相关文章! **Categories:** WordPress ---