0
votes

I am trying to make a load more button that will load more images from my ACF Gallery using AJAX. But to do this I need to be able to use wp_query so that I can set the amount of posts per page. So is it possible to convert the following code into a wp_query?

<?php 

    $images = get_field('images');

    if( $images ): ?>
        <?php foreach( $images as $image ): ?>
            <div class="col-4 p-0">
                <a href="<?php echo $image['url']; ?>">
                    <img src="<?php echo $image['sizes']['gallery_size']; ?>" alt="<?php echo $image['alt']; ?>" />
                </a> 
             </div>
        <?php endforeach; ?>
    <?php endif; ?>
1
Don't found any straight forward approach but you can limit the number of images to be displayed by managing counter variable. Break the loop once your index reach & on ajax call load all. - Parth Goswami

1 Answers

0
votes

Have you looked at: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

Basically you can query ACF by a meta_query using WP_Query and use WordPress's paginate_links() method to load more with your AJAX.

Hope that helps.