【问题标题】:advanced custom fields checkbox in WordPressWordPress 中的高级自定义字段复选框
【发布时间】:2016-08-20 05:11:55
【问题描述】:

我正在为我的一种自定义帖子类型使用 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>

我该如何解决?我的问题出在哪里?

【问题讨论】:

    标签: php wordpress advanced-custom-fields


    【解决方案1】:

    如果要回显该字段,请替换

    get_field('auth-trans')
    

    有

    get_field('auth-trans')[0]
    

    或者你也可以使用

    the_field('auth-trans');
    

    【讨论】:

      【解决方案2】:

      试试这样吧。

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

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

      【讨论】:

      • 我是在'if'条件下还是在调用'auth-trans'字段时写?
      • 是的,你必须在 if 条件下使用它。
      • 或者你也可以不使用 if 条件。如果该值存在,它将显示或不显示任何内容。 :)
      猜你喜欢
      • 1970-01-01
      • 2015-04-21
      • 2012-08-10
      • 1970-01-01
      • 2014-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多