0

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.

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>
  • Thank you very much. I'll post the result for others when I get it to work. – Joe Barrett Jun 13 at 15:25
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.