Hello all!
I’m experiencing the wonderful world of n8n! And already quite impressed!
However I’m doing something wrong to make my workflow fully work the way I want, suggestions and help are more than welcome:
It looks simple:
- check every x minutes if there is a new post of category Y on wordpress site A (via API)
- if there is a new post that never has been ‘processed’ before continue
- post a new post on wordpress site B (via API)
Step 1 and 3 are working already perfectly! The workflow looks like this:
Of course the tricky thing is the function node, I tried to reuse a Twitter version from another support thread but it doesn’t work :
const staticData = getWorkflowStaticData('global');
const newWPIds = items.map(item => item.json["ID"]);
const oldWPIds = staticData.oldWPIds;
if (!oldWPIds) {
staticData.oldWPIds = newWPIds;
return items;
}
const actualNewWPIds = newWPIds.filter((id) => !oldWPIds.includes(id));
const actualNewPosts = items.filter((data) => actualNewWPIds.includes(data.json['ID']));
staticData.oldWPIds = [...actualNewWPIds, ...oldWPIds];
return actualNewPosts;
What do I have to do to make this work?
Thanks already for helping me out.
Kind regards,
Marcel.