Using this Meteor package redcap3000:wordpress-json-api for displaying wordpress posts via wordpress api in json format, I managed to successfully display them in my meteor app. However I need to save the posts in my mongo db collections AS WELL AS updating the collection automatically when a new post is available at my wordpress site, how can i do that?
here is what i have so far.
` MyCollection = new Mongo.Collection(‘Articles’);
saveArticles: function() {
Meteor.call(‘wordpress’,‘http://my-wordpress-site/?json=get_posts&count=10’, function(err, res) {
var data = res.title;
MyCollection.insert(data);
}
}
Meteor.subscribe(“wordpress”,“http://my-wordpress-site/?json=get_posts&count=10”);
Session.setDefault(“wp-json-api-url”,“http://my-wordpress-site/?json=get_posts&count=10”);`
server side code
`Meteor.startup(function(){
Meteor.setInterval(function(){Meteor.call(‘http://my-wordpress-site/?json=get_posts&count=10’);}, 1000);
});
Meteor.publish(“wpPost”,function(id){})`
error
While processing files with ecmascript (for target web.browser): lib/collections.js:6:22: Unexpected token (6:22)
which relates to the first line of this code i (the one i put above, in my client folder)
saveArticles: function() { Meteor.call('wordpress','http://my-wordpress-site/?json=get_posts&count=10', function(err, res) { var data = res.title; MyCollection.insert(data); } }
overall i’m not sure if i’m going the right direction.