Created
January 21, 2014 08:18
-
-
Save wgroenewold/8536188 to your computer and use it in GitHub Desktop.
Gist to decode the Wordpress attachment ID's from a ACF Gallery custom field
This file contains hidden or 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
var gallerycf = json.post.custom_fields.gallerij[0]; | |
gallerycf = gallerycf.split('{'); | |
gallerycf = gallerycf[1].split(';'); | |
var items = []; | |
for(i=0; i<gallerycf.length; i++){ | |
if(i % 2 !== 0){ | |
items.push(gallerycf[i]); | |
} | |
} | |
var items2 = []; | |
for(i=0;i<items.length;i++){ | |
items[i] = items[i].substring(5); | |
items[i] = items[i].slice(0,-1); | |
items[i] = parseInt(items[i], 10); | |
items2.push(items[i]); | |
} | |
console.log(items2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment