I have some external data I'm calling from an API. The data is WordPress posts objects I'm fetching via the WordPress API.
I'm using the HTTP package and my code looks like this.
server.js
const articleIncoming = HTTP.call( 'GET', 'http://myUrl/wp-json/wp/v2/posts', {}, function( error, articleIncoming ) {
if ( error ) {
console.log( error );
} else {
console.log( articleIncoming );
});
Where articleComing
is the response. One WordPress post object looks like this in the console. This data updates with new posts on a regular basis and I would like the collection Posts
, which I'm loading this data into, to reflect that.
Now that I have my data, I want to add these posts to a collection called Posts
but I'm having difficulty.
server.js
const articleIncoming = HTTP.call( 'GET', 'http://myUrl/wp-json/wp/v2/posts', {}, function( error, articleIncoming ) {
if ( error ) {
console.log( error );
} else {
console.log( articleIncoming );
});
Meteor.methods({
'Posts.insert'(articleIncoming) {
return Posts.insert({
articleIncoming,
});
},
});
How can I save the constantly updating WordPress posts into the collection, in a way that updates when a new post is published in WordPress?
Without post duplication