Support

Account

Home Forums General Issues Array for get_field( )

Helping

Array for get_field( )

  • Hallo Community,

    I have a DIV container that is completely built in the ACF.
    Various articles / products / articles are listed here

    I’ve created a CPT for this, as well as my own template.
    An ACF with the field type (contribution object) runs in this template.

    We currently have 18 properties listed here.

    At the moment I repeat my DIV container 18 times in the code and “only” change the number in get_field ().

    That’s a lot of code, of course. I would like this to be easier.
    But what is the best way to solve this with a loop / array?

    Can someone help me there?

    
    <div class="one_field">    
    <div class="active-goods-item ">
       <div class="tab_content active ">
           <ul class="produ-list clearfix js-brandsItem moregoods_color ">
               <li class="googleTempTwo subjectGoodItem">
                   <div class="pro-content">
                       <div class="goods-img pr">
                            <?php $angebot_1 = get_field( 'angebot_1' );
                                    if ( $angebot_1 ) {
                                           // $post = $angebot_1;
                                            $image = get_field( 'image' );
                                            $size = 'full'; // (thumbnail, medium, large, full or custom size)
                                            $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( ), 'large');
                                            if ( $image ) {
    //                                            echo '<pre>'; var_dump( $image ); echo '</pre>';
                                                echo '
                                                    <img 
                                                    width="300" 
                                                    height="300" 
                                                    src="' . esc_url( $image['url'] ) .'"
                                                    alt="' . esc_attr( $image['alt'] ) . '"
                                                    class="img-responsive product-img wp-post-image box_image" /> ';
                                                    
                                                $lager = get_field ('lager'); 
                                                if ( $lager) { 
                                                    echo '<span 
                                                            class="goods_label" 
                                                            style="background-color: #00CC99;color: #ffffff;bottom:8px;border-color: #00CC99;">
                                                        <span>Versand aus Deutschland</span>
                                                    </span> ';
                                                    }
                                               
                                                }
                                                else {
                                                echo '<img 
                                                        width="300" 
                                                        height="300" 
                                                        src="/wp-content/uploads/2019/09/cropped-Logo_512x512-4.png" 
                                                        alt="'. esc_attr( $image['alt'] ).'"  /> ';
                                                echo'            <span 
                                                            class="goods_label" style="background-color: red;color: #ffffff;bottom:8px;">
                                                                <span>Leider kein Bild vorhanden</span>
                                                            </span> ';
                                                }
                                            wp_reset_postdata();
                                        }        
    
                            ?>
                       </div>
                   </div>
               </li>
           </ul>
       </div>
                            <?php $angebot_1 = get_field( 'angebot_1' );     
                                if ( $angebot_1 ) {
                                $post = $angebot_1;
                                $listenpreis = get_field(listenpreis);
                                $aktionspreis = get_field(aktionspreis);
                                $gearbestlink = get_field(gearbestlink);
                                $gutscheincode_gearbest = get_field(gutscheincode_gearbest);
                                setup_postdata( $post );
                                    echo '<p class="goods-title">
                                   
                                    <a href="'. get_the_permalink().'">'. get_the_title().'</a>
                                        </p> ';
                                    echo '<p class="">
                                        Gutscheincode: '. $gutscheincode_gearbest.'
                                    </p> ';
                                    echo '<p class="goodOrinalPrice" 
                                        style="text-decoration: line-through; display: inline-block; vertical-align: middle;">
                                        '.$listenpreis.'
                                    </p> ';
                                    echo '<p class="goodOrinalPrice">
                                                <p class="price_original">
                                                    <a href="'. $gearbestlink.'" 
                                                    class="gearrbestlink" 
                                                    target="_blank"> '. $aktionspreis.'
                                                    </a>
                                                </p>
                                    </p>';
                                    echo '<p class="goods-buy showCart ">
                                            <a href="'. $gearbestlink.'">
                                            </a>
                                    </p>';
                            wp_reset_postdata(); 
                            }
                            ?>
    </div>
    </div>
    
    

    https://gist.github.com/MrThiemann/de125a0ef1fdd3a85c433dacdfdb8fad

  • It’s not very clear what the whole set-up is. So, you have a custom post type and a custom field called “angebot_1” is shown for all posts of this post type? Or do you have 18 custom fields where each custom field is shown in one of the 18 custom post entries? This sounds overly complicated.

    Please enlighten me/us.

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

You must be logged in to reply to this topic.