Skip to content

Instantly share code, notes, and snippets.

@mdunbavan
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save mdunbavan/56d7bf823f7f1f48ec1e to your computer and use it in GitHub Desktop.

Select an option

Save mdunbavan/56d7bf823f7f1f48ec1e to your computer and use it in GitHub Desktop.
Getting objects in json.
work_content: Array[4]
Object 0:
acf_fc_layout: "content_area"
text: "<p>test text</p>↵"
Object 1: Object
acf_fc_layout: "gallery"
images:
Object 2: Object
acf_fc_layout: "full_screen_video"
video_url: "&lt;iframe width=&quot;560&quot; type=&quot;text/html&quot; height=&quot;315&quot; id=&quot;windows&quot; src=&quot;//www.youtube.com/embed/1S7He-ShRLg?version=3&amp;enablejsapi=1&amp;html5=1&quot; frameborder=&quot;0&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;/iframe&gt;"
Object 3: Object
acf_fc_layout: "2_column_images"
image_1: Object
image_2: Object
success: function ( dataS ) {
//List some global variables here to fetch post data
// We use base as our global object to find resources we need
var base = dataS[0];
console.log(base);
var postContent = base.content;
var postTitle = base.title;
// Main Image ACF object
var featuredImage = base.meta.main_image;
// Gallery ACF object
var nodes = base.meta.work_content;
// Simple ACF object
//var textArea = base.meta.work_content[1];
var items = [];
var layoutNames = [];
for(var i = 0; i < nodes.length; i++)
{
var layout = nodes[i];
layoutNames.push(layout.acf_fc_layout);
//console.log(layout);
// items.push( layout.acf_fc_layout['gallery']);
// console.log(layout);
};
console.log(layoutNames);
// This outputs below
// Object {acf_fc_layout: "content_area", text: "<p>test text</p>↵"},
// Object {acf_fc_layout: "gallery", images: Array[1]},
// Object {acf_fc_layout: "full_screen_video", video_url: "&lt;iframe width=&quot;560&quot; type=&quot;text/h…llowfullscreen allowfullscreen&gt;&lt;/iframe&gt;"},
// Object {acf_fc_layout: "2_column_images", image_1: Object, image_2: Object}acf_fc_layout: "2_column_images"image_1: Objectimage_2: Object__proto__: Object}
$(layoutNames).each(function (){
// This now loops through all objects from layouts and retrieves them.
for(var i = 0; i < nodes.length; i++)
{
var layout = nodes[i];
//if( layout.acf_fc_layout==$(this).val() );
if ( layout.acf_fc_layout == $(this).val() && $(this).val() == "gallery"){};
//Perform Operation either image / video / page layout
//console.log(layout);
};
});
// $('<div>', {
// "class":'loaded',
// html:items.join('')
// }).appendTo(projectContainer);
},
cache: false
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment