2016-08-20 127 views
1

我在WordPress中使用高级自定义字段复选框功能来实现自定义帖子类型之一。我在复选框中有两个项目。WordPress中的高级自定义字段复选框

  • 作家
  • 批判者

我只是想打印这是从WordPress管理面板选择是正确的。提交的名称是auth-trans

我在我的代码中调用它,但它显示array,而不是正确的。这是我的一些代码。

<div class="col-md-11 col-sm-11 col-xs-12"> 
    <?php $args = array('post_type' => 'Author', 'posts_per_page' => 5); 
    $loop = new WP_Query($args); 
    while ($loop->have_posts()) : $loop->the_post(); ?> 
    <a class="writer-link col-md-12 col-sm-12 col-xs-12" href="<?php post_permalink(); ?>"> 
     <div class="writer-row1 col-md-12 col-sm-12 col-xs-12"> 
       <div class="col-md-2 col-sm-3 col-xs-12 image-right"> 
        <?php the_post_thumbnail(array('class' => 'img-responsive')); ?> 
       </div> 
       <div class="col-md-10 col-xs-12 col-sm-9 col-xs-12 pull-right writer-content"> 
        <h3><?php the_title(); ?></h3> 
        <?php if (get_field('auth-trans')) { 
         echo '<h4>'.get_field('auth-trans').'</h4>';} ?>  
        <?php if (get_field('writer-bio')) { 
         echo '<p>'.get_field('writer-bio').'</p>';} ?> 

        <span>...</span> 
       </div> 
     </div> 
    </a> 

    <?php endwhile; // End of the loop. ?>   

</div> 

我该如何解决这个问题,我的问题在哪里?

回答

0

有一个这样的尝试。

<?php the_field('auth-trans'); ?> 

如果您遇到任何问题,请告诉我。

+0

我写的“如果”条件,或当调用'auth-trans'字段? – mkafiyan

+0

是的,你必须使用它,如果调和。 –

+0

或者,如果条件也可以使用。如果值存在,它将显示或不显示任何内容。 :) –

1

如果你想呼应场然后更换

get_field('auth-trans') 

随着

get_field('auth-trans')[0] 

或者你也可以使用

the_field('auth-trans');