简体   繁体   中英

wp_query for an Advanced Custom Fields gallery

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; ?>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM