php - List all ACF field values across every post on one page

I used an ACF repeater field for data sheetsinstruction manual download links of products in woocommerce. There's

I used an ACF repeater field for data sheets/instruction manual download links of products in woocommerce. There's 50 products and each has 1 to 4 download links on their product page. I've been searching for a way to list all the links form all 50 products on one page the way you would query all posts on a page in a list. I don't even know where to start looking and I didn't see anything specific on the ACF forums.

I used an ACF repeater field for data sheets/instruction manual download links of products in woocommerce. There's 50 products and each has 1 to 4 download links on their product page. I've been searching for a way to list all the links form all 50 products on one page the way you would query all posts on a page in a list. I don't even know where to start looking and I didn't see anything specific on the ACF forums.

Share Improve this question asked Jun 12, 2019 at 22:20 Joe BarrettJoe Barrett 236 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

You want to start here and here.

Essentially you're just looping through all your posts like normal and then adding some custom fields into it.

Be sure to reference the Repeater Field documentation.

This should work inside a loop. Notice you'll need your post ID.

<ul>
    <?php

    if( have_rows('YOURREPEATERFIELDNAMEHERE', 'POSTIDHERE') ):

        while ( have_rows('YOURREPEATERFIELDNAMEHERE', 'POSTIDHERE') ) : the_row(); ?>


            <li><?php echo get_sub_field('SUBFIELDNAMEHERE'); ?></li>

       <?php endwhile;

    else :

        // no rows found

    endif;

    ?>


    <?php endwhile; ?>
</ul>

I used this.

<?php 

$posts = get_posts(array(
    'posts_per_page'    => -1,
    'post_type'         => 'product',
    //'orderby'         => 'title',
    //'order'           => 'DESC',
    'tax_query' => array( array(
        'taxonomy'         => 'product_cat',
        'field'            => 'slug', // Or 'term_id' or 'name'
        'terms'            =>  'winter-products' // A slug term
        // 'include_children' => false // or true (optional)
    )),
));

if( $posts ): ?>
    <h3>Winter Products</h3>
    <ul>

    <?php foreach( $posts as $post ): 

        setup_postdata( $post );
        $post_id = get_the_ID();

    ?>


            <?php if( have_rows('extra_info', $post_id) ): ?> 
                <li>

            <strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong> 

                <ul>

                <?php while( have_rows('extra_info', $post_id) ): the_row(); ?>

                    <li><a href="<?php the_sub_field('link_url'); ?>" target="_blank"><?php the_sub_field('link_title'); ?></a></li>

                <?php endwhile; ?>

                </ul>

            <?php endif; ?>
        </li>

    <?php endforeach; ?>

    </ul>

    <?php wp_reset_postdata(); ?>

<?php endif; ?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745401889a4626140.html

相关推荐

  • php - List all ACF field values across every post on one page

    I used an ACF repeater field for data sheetsinstruction manual download links of products in woocommerce. There's

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信