尝试循环循环高级自定义字段pro函数.php



我正在使用WordPress使用高级自定义字段,但是我有一个问题使其与创建短代码一起工作。我想用一个可以添加到Visual Composer中的简短代码来驱动我的团队成员的帖子类型,但我遇到了一个错误,这是我尝试过的。

function team(){ 

   // get posts
   $posts = get_posts(array(
    'post_type'         => 'team-member'
   ));

     if( $posts ): ?>
<?php foreach( $posts as $post ): 
   setup_postdata( $post );       
  $description = get_field('description');
  $name = get_field('name');  
  ' i want to loop here to print out every team member 
    $cnt='';
    $cnt.='<sction class="row ev-home-4">';
        $cnt.='<div class="col-sm-12 owl-carousel owl-theme" id="teams">';
            $cnt.=' <div class="item ev-home-4-block">
                        <div class="col-sm-12 ev-home-4-block-1">
                            <img src="'.get_site_url().'/wp-content/uploads/2017/11/test-1.png" class="img-responsive">
                            <div class="row row2 ev-home-4-block-2">
                                <h2>'.$name.'</h2>
                                <small>'.$description.'</small>
                            </div>
                        </div>
                    </div>';


        $cnt.='</div>';
    $cnt.='</sction>';
    <?php endif; ?>
<?php endforeach; ?>
    return $cnt;
}
add_shortcode('team','team');

但是我遇到以下错误

https://preview.ibb.co/ijsi5g/chrome_2017_12_07_22_37_54.54.png

也许类似:

function team() {
$args = array('post_type' => 'team-member');
$return_string ="";
$the_query = new WP_Query( $args );
    while ( $the_query->have_posts() ) : $the_query->the_post();
        $return_string .= 'Your html/images etc here here';
    endwhile;
wp_reset_postdata();
return $return_string;
}
add_shortcode( 'yourShortCodeNameHere', 'team' );

最新更新