I am using a repeater field from Advanced Custom Fields to create multiple photo galleries. There are 4 pages and each page has multiple image galleries. Because of this, I want to reduce load by using a single external PHP file to generate the content and AJAX to only load one gallery at a time.
I am not quite sure how to accomplish this, because since the ACF fields are being defined in an external file, it doesn't know what page to grab the fields from.
Here is my JavaScript so far:
var passObject = {};
$.ajax({
url:"<?php bloginfo('template_directory'); ?>/inc/galleries.php",
type: 'POST',
data: passObject,
success: function(resp) {
$('#photos').append(resp);
}
});
And here is the content of galleries.php:
<div class="photos">
<h1>Photo Gallery</h1>
<?php if( have_rows('gallery') ): ?>
<?php while( have_rows('gallery') ): the_row();
// vars
$photo = get_sub_field('photos');
?>
<div class="image"><img src="<?php echo $photo['sizes']['gallery-thumb']; ?>" alt="<?php echo $photo['alt']; ?>" /></div>
<?php endwhile; ?>
<?php endif; ?>
</div>