Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tools: Merge existing content in when syncing from live site. #22

Merged
merged 1 commit into from
Jul 27, 2022

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Jul 27, 2022

See #18. The sync script pulls down content from a given URL (the staging site, currently). This created duplicate content when run if you've already got content from yarn setup:wp. The IDs from the import into an empty site are the same, so we can just quickly use get_post to check for existing content. If we have an existing post, this merges the new content into the existing array, so that when wp_insert_post is run, it has the existing ID and updates it.

How to test the changes in this Pull Request:

  1. Clean your site with yarn wp-env clean all
  2. Run yarn setup:wp to set up content
  3. Run yarn setup:refresh to sync down the content -- you should now have a page called "Steve's test", but no duplicate pages.

@ryelle ryelle added the [Component] Tools Build tools, packages, etc label Jul 27, 2022
@ryelle ryelle requested a review from tellyworth July 27, 2022 20:34
@ryelle ryelle self-assigned this Jul 27, 2022
@tellyworth
Copy link
Contributor

Looks good to me. I did wonder if we should handle conflicts (where local edits have been made) but that can be a separate issue if it's needed.

@tellyworth tellyworth merged commit 8020f92 into trunk Jul 27, 2022
@tellyworth tellyworth deleted the update/sync-merge-existing branch July 27, 2022 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Tools Build tools, packages, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants