Last active
March 23, 2021 07:13
-
-
Save ilovefreesw/e9a53f3e077916779fb40f1cee9ed0df to your computer and use it in GitHub Desktop.
Google Sheets Apps Script to get WordPress Post ID from URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Convert WordPress URLs to Post ID in Google Sheets
Extract Slug from URLs in Google Sheets
Get Post ID from WordPress URL Google Sheets