我正在使用带有wordpress的高级自定义字段,但我遇到了创建短代码的问题。我想用我可以添加到视觉作曲家的短代码来驱动我的团队成员帖子类型,但是我得到了一个错误,这就是我尝试过的。
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.png
答案 0 :(得分:0)
可能是这样的:
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' );