After Wordpress import - bulk update Featured Image (SQL)?

Hello. First post. Thanks to the great documents, I successfully imported hundreds of Posts from my Wordpress site. I’ve manually added some Featured Images to Posts in Ghost, but the vast bulk don’t have any.

Is there any way to do a Bulk Update, even using SQL (which I know). In pseudo-code :grinning: :

If Tag is Movies
Updated Featured_Image to <url for movie picture>

Or set a System-Wide default for existing Posts?
Thanks!

Have a look at the admin api. It should be pretty doable, but post if you get stuck!

Thank you. And back up to json first, of course.

I use PowerShell on Windows, via the standard Terminal. I got the Content API working pretty quickly. If there’s any interest I could write up my learnings, with some annotated examples. If this isn’t the place to ask, just let me know the appropriate section.

1 Like

Thanks again. I’ve got a basic JavaScript script working. In the last few days, I’ve gone from the Hello World level to being able to get the code (below) working. It’s pretty crude, but it works for me. I’m updating the featured-image for each (primary) Tag

const GhostAdminAPI = require('@tryghost/admin-api');

const api = new GhostAdminAPI({
  url: 'https://www.mywebsite.etc',
  key: '673etcetc',
  version: "v5.0",
});


// simple timer, gives user a chance to cancel
function wait(ms){
   var start = new Date().getTime();
   var end = start;
   while(end < start + ms) {
     end = new Date().getTime();
  }
}

// set the Primary tag (name)
ptag = 'artist'

// Give the user a chance to exit (Ctrl-c on Windows). Crude, could be a 'yes' to confirm then loop, but I don't know JavaScript that well.
console.log(' ');  
console.log('Doing the primary tag: ', ptag);
console.log(' ');  
console.log('*** Bulk update in 5 seconds. Ctrl-C to cancel!');
console.log(' ');  
wait(5000);  //5 seconds in milliseconds
console.log('Ok, starting');


img = 'https://plus.unsplash.com/premium_photo-1682745684850-7229f196b0c9?w=500&auto=format&fit=crop&q=60&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MXx8bXVzaWNpYW5zfGVufDB8fDB8fHww'

let i = 1   // counter for loop

api.posts.browse({
    filter: `primary_tag: ${ptag}`,
	limit: '50'   // should be ok for my site
})
.then((posts) => {
    posts.forEach((post) => {
        console.log(i, "doing:", post.title);
		api.posts.edit({"id": post.id, "updated_at": post.updated_at, "feature_image": img });
		i++;
    });
})
.catch((err) => {
    console.error(err);
});