【问题标题】:wp_query for an Advanced Custom Fields gallery高级自定义字段库的 wp_query
【发布时间】:2019-07-14 09:48:22
【问题描述】:

我正在尝试制作一个加载更多按钮,该按钮将使用 AJAX 从我的 ACF 库加载更多图像。但要做到这一点,我需要能够使用 wp_query 以便我可以设置每页的帖子数量。那么是否可以将下面的代码转换成 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; ?>

【问题讨论】:

  • 没有找到任何直接的方法,但您可以通过管理计数器变量来限制要显示的图像数量。一旦你的索引到达 & on ajax call load all,就打破循环。

标签: php ajax advanced-custom-fields


【解决方案1】:

你看过了吗:https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

基本上,您可以使用 WP_Query 通过 meta_query 查询 ACF,并使用 WordPress 的 paginate_links() 方法通过 AJAX 加载更多内容。

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-24
    • 1970-01-01
    • 2017-12-16
    • 2013-07-14
    • 2013-11-25
    • 2012-08-10
    • 1970-01-01
    • 2014-03-23
    相关资源
    最近更新 更多