2016-08-20 71 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'); 
相關問題