Skip to content

Instantly share code, notes, and snippets.

@ilovefreesw
Last active March 23, 2021 07:13
Show Gist options
  • Save ilovefreesw/e9a53f3e077916779fb40f1cee9ed0df to your computer and use it in GitHub Desktop.
Save ilovefreesw/e9a53f3e077916779fb40f1cee9ed0df to your computer and use it in GitHub Desktop.
Google Sheets Apps Script to get WordPress Post ID from URL
function getPostID(link) {
var slug = link.split("/").pop().split(";")[0].replace(".html","");
var url = 'https://www.ilovefreesoftware.com/wp-json/wp/v2/posts?slug='+slug;
var response = JSON.parse(UrlFetchApp.fetch(url).getContentText())
return response[0]['id'];
}
//funtion to get sluf from URL only
/*function getSlug(data) {
slug = data.split("/").pop().split(";")[0].replace(".html","");
return slug;
}*/
@ilovefreesw
Copy link
Author

Convert WordPress URLs to Post ID in Google Sheets

Extract Slug from URLs in Google Sheets

Get Post ID from WordPress URL Google Sheets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment