Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

John Nixon
17,690 PointsAnyone had any experience using a JSON file to create and update a custom post types posts?
I'm working on a project where the client has requested we bring in a feed from a third party service. They've provided us with a JSON to get the content. I've followed along with the tutorial on building a plugin and it is very similar to what I need. The biggest difference is I need the entries to save and update as posts. I have a lot of it done, but its not quite where I would like it to be. I can't get posts to update without them duplicating and I've not even gotten into modifying the AJAX yet. If you have done this or know of any resources that you can point me to it would be a big help.
3 Answers

Daron Spence
7,895 PointsJohn, for this to work, you'll need to make sure each new "post" from the JSON feed has some sort of unique identifier. When doing your loop to create the new posts, you can check if a post already exists for that unique ID, and if it does, there are functions to update that post information and meta on the fly.
As a side note, you'll definitely want to cache that JSON feed data or run it on a CRON job so that way your page loads aren't insane. This is especially true if the feed has hundreds of posts in it.

Ryan Carter
726 PointsHey John,
Did you manage to get this working?

John Nixon
17,690 PointsI did

Christopher Nowlan
2,582 PointsHi John, Could you post the working example?
John Nixon
17,690 PointsJohn Nixon
17,690 PointsThanks for the input, I've already gotten the unique identifier set up and as far as the page load time its not a big deal because as I said they are saving in the database as actual posts. Where I'm stuck at now is getting the posts to update, and getting the ajax going but here is a snippet of how I'm currently adding the posts