Support

Account

Forum Replies Created

  • (posted twice accidentally)

  • I will try to – can you share the code you are using to get the titles? By titles do you mean the title attribute of images? If so and that’s working, then if I’m not mistaken (which often I am) you should be able to get url, alt, caption in the same way.

  • Thanks John, that helped. Now that I have that working, I have another issue, I will start a new thread here. Thanks for all your help, as usual!
    Ben

  • If I’m understanding you right, it sounds like you need the code from the Gallery field’s main page? I’ll paste it here.
    ‘<?php
    $images = get_field(‘gallery’);
    if( $images ): ?>

    <?php endif; ?>’

    https://www.advancedcustomfields.com/resources/gallery/

    Does that help?

  • Turns out – as usual with me – it was much simpler. I used a Woo shortcode that displays products (the way i wanted, with all the product details) and put it inside the loop that gets the PostID for the three products, set the PostID to a var, and it is almost working.

    It is working, except i need to adjust the loops syntax somehow:

     // check if the repeater field has rows of data
        if( have_rows('products_to_display_repeater') ):
    
            // loop through the rows of data
            while ( have_rows('products_to_display_repeater') ) : the_row();
    
                // vars
                $product_id = get_sub_field('product_complete_the_look');
                
                // get IDs from vars for Woo shortcode
                echo do_shortcode("[products ids='$product_id' limit='1' columns='1' orderby='date' order='desc']");
    
                // display a sub field value
                ?> 
                <?php the_sub_field('product_complete_the_look'); ?>
                <br>
                <?php 
    
            endwhile;
    
        else :
    
            // no rows found
    
        endif;

    The above works but because of echo do_shortcode("[products ids='$product_id' limit='1' columns='1' orderby='date' order='desc']"); I get three products each as 1 column and 1 row. I need one row with three columns.

    So the shortcode is being looped and called three times, once for each PostID. I need to only call the shortcode once and loop only the '$product_id' within the shortcode, thereby have three PostIds in the shortcode. Oh and they need to be comma separated.

    If anyone has input that’s great but I might figure it out…

  • Maybe I should be using the code from Woocommerce’s template archive-product.php as that page displays products the same way I need to. So maybe i should try that code as a starting point and replacing the appropriate pieces of code with ACF fields (the three products chosen on the product’s edit page.)

    Wanted to add that idea which i am still looking into deeper.

  • Thank you John for the input – turn out, i needed to add 'options' after the field names in the PHP, so i figured it out. Thanks again!

  • Thanks @john i really appreciate that!

    I am still having trouble getting it to work. I first tried a few of the code examples from that link:

      <?php
                $rows = get_field('product_categories_icons');
                if($rows)
                {
                    echo '<ul>';
    
                    foreach($rows as $row)
                    {
                    echo '<li>sub_field_1 = ' . $row['name'] . ', sub_field_2 = ' . $row['link'] .', etc</li>';
                    }
    
                    echo '</ul>';
                }
                ?>
    
                <?php if(get_field('product_categories_icons')): ?>
                    <ul>
                    <?php while(has_sub_field('product_categories_icons')): ?>
                        <li>sub_field_1 = <?php the_sub_field('name'); ?>, sub_field_2 = <?php the_sub_field('icon'); ?>, etc</li>
                    <?php endwhile; ?>
                    </ul>
                <?php endif; ?>

    Neither of which shows anything on the page. The site is on WPE and i have been clearing the cache with every try.

    Also i do not at the moment have access to the database which would be helpful for me just to confirm what’s coming from where (since ACF is implemented in both places like i mentioned.)

    So i am looking at other pages’ ACF code and am trying to emulating that. I have added this new field i am trying to display to the acf-register-field-groups.php as there are fields that only exist there, not in the GUI ACF, that are working and on pages.

    I am spending hours on this which is crazy, but there’s still something i am not doing right or seeing.

    Lastly i tried this:

    
    <?php if(get_field('product_categories_icons')) : ?>
                    <?php echo '<h1>true</h1>'; ?> 
                    <?php while(has_sub_field('product_categories_icons')): ?>
                        <li>icon = <?php echo get_sub_field('icon'); ?>
                        name = <?php echo get_sub_field('name'); ?></li>
                        <li>icon = <?php echo the_field('icon'); ?>
                        name = <?php echo the_field('name'); ?></li> 
                        <li>name = <?php echo the_sub_field('name'); ?>
                        icon = <?php echo the_sub_field('icon'); ?></li>
                    <?php endwhile; ?>
       <?php endif; ?>

    And since <?php echo '<h1>true</h1>'; ?> doesn’t print under the if something higher up is restricting this field’s display.

    If you have any ideas i’m all ears.

    Thanks!

Viewing 9 posts - 26 through 34 (of 34 total)