Skip to content

Instantly share code, notes, and snippets.

@wgroenewold
Created January 21, 2014 08:18
Show Gist options
  • Save wgroenewold/8536188 to your computer and use it in GitHub Desktop.
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
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