Support

Account

Forum Replies Created

  • Hey John,

    I had to hop off this project for a little, but today I had time to get back to it, and I was finally able to wrap my head around it. Thanks for your help!

    Firstly, I didn’t realize I could enter more than one value in the repeater input, I was duplicating the input and then entering a value, which wasn’t working because the input I was duplicating, obviously wasn’t being called in my code, but once I added more values to my repeater input I was calling in my code, I was able to output them.

    Then, instead of setup_post_data($post); I used wc_setup_product_data($post); which didn’t break the entire site, like setup_post_data(); did.

    Again, thanks for your help!

    -Cheers

  • Hey John,

    Yeah, it does, it shows “int()” with the products id.

  • Well, thanks for helping, I tried for quite a bit of time, still got nothing to work at all, I even adjusted how I declared the global $post.

    This is where I last left off not too sure where to go from here, maybe it’s how I set up my ACF http://ussawssdev.wpengine.com/wp-content/uploads/2021/06/Capture.png

    
    <div id="featured" class="product_slider-1">
    <?php if( have_rows('featured_product_repeater') ) { ?>
    <div class="testing_prod_div">
       <?php 
            while (have_rows('featured_product_repeater')) {
              the_row();
              $posts = get_sub_field('product_2');
              foreach ($posts as $post) {
                   var_dump($post);
                   setup_post_data($post);
                   wc_get_template_part('content', 'product');
                }
             }
          ?>
       </div>
    <?php wp_reset_postdata(); } ?>
    <div>Testerrrrrrs</div>
    </div>
  • If I could provide more detail please let me know…

  • Like here’s the full code snippet

    <div id="featured">
    <?php if( have_rows('featured_product_repeater') ) { ?>
    <div class="product_slider-1">
    <?php 
            while (have_rows('featured_product_repeater')) {
              the_row();
              $posts = get_sub_field('featured_product_repeater');
              foreach ($posts as $post) {
                   var_dump($post);
                   // setup_post_data($post);
                   // wc_get_template_part('content', 'product');
                }
              }
          ?>
       </div>
    <?php wp_reset_postdata(); } ?>
    </div>
  • After doing some digging it seems like my issue is steaming from setup_post_data($post);

              foreach ($posts as $post) {
                   var_dump($post);
                   // setup_post_data($post);
                   // wc_get_template_part('content', 'product');
                }

    Whenever I comment these in it breaks, I don’t think it likes the id data.

  • The first <div class=”product_slider-1″> out puts correctly, however once I get <div class=”product_slider-2″> I’m changing it.

  • Sorry, I don’t know why I can’t wrap my head around this, I think I’ve just been stressed out or something. I’ve tried a few other variations myself with the foreach loop, and then now yours am I missing something here? What else should I check?
    Here’s my full code I’m testing with

    
    <?php
       // Featured products feilds
       $featuredProductTitle = get_field('featuredproducttitle');
       
       $featuredProductSlide = get_field('featured_products_repeater');
       
       $featuredBestSellerSlide = get_field('best_selling_products_repeater');
       
       var_dump($featuredProductSlide);
    ?>
    <br>
    <h2>Data</h2>
    <?php
       var_dump($featuredBestSellerSlide);
       ?>
    
    <!-- Slider Menu -->
    <div class="product_slider_title_section">
       <div class="slider_title">
          <h2><?php echo $featuredProductTitle ?></h2>
          <hr class="title_line">
       </div>
       <div class="product_slider_controls">
          <h3><a id="featured">Featured</a></h3>
          <h3><a id="best_selling">Best Seller</a></h3>
          <h3><a id="new_arrivals">New Arrivals</a></h3>
       </div>
    </div>
    
    <div id="featured">
       <div class="product_slider-1">
       <?php if(have_rows('featured_products_repeater')):?>
          <?php while( have_rows('featured_products_repeater')): the_row(); ?>
         <?php  $args = array(
             	'post_type' => 'product',
             	'posts_per_page' => 3,
             ); 
             $loop = new WP_Query( $args );
             
             if ( $loop->have_posts() ) {
             
             	while ( $loop->have_posts() ) : $loop->the_post();
             
             		wc_get_template_part( 'content', 'product' );
             
             	endwhile;
             
             } else {
             	echo __( 'No products found' );
             }
             
             ?>      
          <?php endwhile;?> 
       </div>
       <?php endif;?>
    </div>
    
    <div id="best_selling">
       <?php if (have_rows('best_selling_products_repeater')) { ?>
          <div class="product_slider-2">
          <?php 
             while (have_rows('best_selling_products_repeater')) {
                the_row();
                $posts = get_sub_field('best_selling_product');
                foreach ($posts as $post) {
                  setup_post_data($post);
                  wc_get_template_part('content', 'product');
                }
             }
             ?>
          </div>
       <?php wp_reset_postdata(); 
       } ?>
    </div>
    
    <div id="new_arrivals" class="product_slider-3">
       <div>TEST TEST</div>
       <div>TEST TEST</div>
    </div>
    

    Also, I can 100% confirm that those are the correct field names.

  • Hey, so this snippet was helpful but I’m still not getting any data output, the link includes foreach loop, is this implying that I need foreach loops within the while loops? -Kinda weird if it is no?

  • Hey John,

    Thanks for the link! -The subfields contains post object

  • Hi John,

    My apologies so, I’m attempting to display three different slides, each slide can display 3 different products. I’m currently not calling any subfields. I’m just calling the parent fields which are the following.

    $featuredProductSlide = get_field('featured_products_repeater');
    
    $featuredBestSellerSlide = get_field('best_selling_products_repeater');

    Maybe there’s a resource link to help me understand this better? -I feel like I’m way off now. Ha!

Viewing 11 posts - 1 through 11 (of 11 total)