admin管理员组文章数量:1310160
Is there any way to import a basic, exported Wordpress content XML file and have it replace the existing content? What I'm trying to do is synch up two instances of a site (development and staging servers) and all I want to replace is the Page content. When I try to import the XML document it simply states that all the pages already exist and nothing is done. Is it possible to override that warning and replace the content of the pages with the content of the XML?
Is there any way to import a basic, exported Wordpress content XML file and have it replace the existing content? What I'm trying to do is synch up two instances of a site (development and staging servers) and all I want to replace is the Page content. When I try to import the XML document it simply states that all the pages already exist and nothing is done. Is it possible to override that warning and replace the content of the pages with the content of the XML?
Share Improve this question asked Apr 14, 2011 at 19:53 hereswhatididhereswhatidid 2,0982 gold badges20 silver badges31 bronze badges3 Answers
Reset to default 4One option might be to export both XML files, merge them using a file merging tool like http://winmerge, delete all posts and replace with the merged version.
Run A Query to Delete All Staging Posts before Importing From Dev
Because menus and pages are custom post types, this will update all posts, pages, and menus to match your dev site.
Delete all posts in the staging server by running a database query. Note that the code requires setting a userid. modify it if there are more users or run it more than once.
SET @WPUSERID='1'; -- end config -- Delete a,b,c FROM wp_posts a LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id) LEFT JOIN wp_postmeta c ON (a.ID = c.post_id) WHERE a.post_author = @WPUSERID;
Import the XML file that you exported from the Dev site.
Caution: Back up your databases for both dev and staging in case you accidently get them mixed up (you think you're connected to stage for example, and you are really connected to dev when you do the delete) .
Be safe: view posts before deleting
Select * FROM wp_posts a
LEFT JOIN wp_term_relationships b
ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c
ON (a.ID = c.post_id)
WHERE a.post_author = @WPUSERID;
In my case - I'm trying to overwrite the content two of the default pages created by sage with predefined content - the best way to overwrite the page/post content was by using the wp post update
cli command.
wp post update 2 "./assets/page-content.html"
where 2
is the page ID and ./assets/page-content.html
is the path to the file with the new content (you could extract the content from an exported xml if you need to).
https://developer.wordpress/cli/commands/post/update/
本文标签: Import and replace existing pagepost content
版权声明:本文标题:Import and replace existing pagepost content 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741793507a2397799.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论