I wonder if you could please point me in the right direction in terms of what script from the api-demos I should be using for changing the tags on multiple posts at once.
Example:
The site has a total of 100 posts. 40 of them are set to paying members only whereof the remaining 60 are set to public. If I were to remove the paying member tag from those 40 posts, which api-demos file / script should I be using?
Could I use the add-tag-to-all-posts.js file and if so, how would I modify it?
/**
* Add a tag to every post
*
* Note: Assumes you already have the tag created
*
* Usage:
*
* node add-tag-to-all-posts.js https://blah.ghost.io ADMIN_API_KEY slug-of-tag-to-add
*/
if (process.argv.length < 5) {
console.error('Missing an argument');
process.exit(1);
}
const url = process.argv[2];
const key = process.argv[3];
const tag = process.argv[4];
const Promise = require('bluebird');
const GhostAdminAPI = require('@tryghost/admin-api');
const api = new GhostAdminAPI({
url,
key,
version: 'v2'
});
(async function main() {
try {
console.log(`Adding tag ${tag} to ${url}`);
const tagToAdd = await api.tags.read({slug: tag});
console.log('Found tag', tagToAdd);
// Admin API automatically includes tags and authors
// WARNING: If the site is really big (1000s of posts) maybe do this paginated
const allPosts = await api.posts.browse({limit: 'all'});
// convert our list of posts, to a list of promises for requests to the api
const result = await Promise.mapSeries(allPosts, async (post) => {
// Add the tag to the post
post.tags.push(tagToAdd);
// Weird.. we shouldn't need to do this:
delete post.uuid;
delete post.comment_id;
console.log('Updating', post.slug);
// Call the API
let result = await api.posts.edit(post);
// Add a delay but return the original result
return Promise.delay(50).return(result);
});
console.log(`Updated ${result.length} posts`);
} catch (err) {
console.error('There was an error', require('util').inspect(err, false, null));
process.exit(1);
}
}());
Hey @thebear.dev ! These files are, as the repository name suggests - ādemosā. They were meant to solve a problem someone once had when dealing with bulk edits, so there are no ārecipesā around there. Iād find a script thatās the closest to what you are trying to do and modify it a little
Yes, which is what I have done. Iām just not sure how to modify the add-tag-to-all-posts.js script to bulk remove a tag.
If you can help with that, I would appreciate it. If not, Iāll ask around for help. If thereās a way that I missed to bulk remove a specific tag from multiple posts from the Ghost admin - please let me know.
I am asking since we now can choose to turn the portal on / off. If turning it off on a site that has multiple posts tagged as paying members only, the posts are still locked after turning the portal off.