Home Forums General Issues Array for get_field( )


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 '
                                                    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 
                                                            style="background-color: #00CC99;color: #ffffff;bottom:8px;border-color: #00CC99;">
                                                        <span>Versand aus Deutschland</span>
                                                    </span> ';
                                                else {
                                                echo '<img 
                                                        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> ';
                            <?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;">
                                    </p> ';
                                    echo '<p class="goodOrinalPrice">
                                                <p class="price_original">
                                                    <a href="'. $gearbestlink.'" 
                                                    target="_blank"> '. $aktionspreis.'
                                    echo '<p class="goods-buy showCart ">
                                            <a href="'. $gearbestlink.'">

  • 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.