du1462 2013-10-15 09:41
浏览 60
已采纳

高级自定义字段 - 如果/ Else语句带有true / false复选框

I have added a true/false checkbox using Advanced Custom Fields for Wordpress. I want to be able to select an option which amends the page template.

I am adding this option to the Product Category in WooCommerce / Wordpress. I have included this bit of logic in the code.

I have the following code but it does not work. I suspect it is because it is not within the loop. However the code I want to insert includes the loop. Any ideas/guidance on the code is much appreciated

<?php if (is_product_category() && get_field('field_name') == true) { ?>

    <div class="custom-sidebar-right">
            <?php if ( have_posts() ) : ?>
            <?php while ( have_posts() ) : the_post(); ?>
                <?php woocommerce_get_template_part( 'content', 'product' ); ?>                 
            <?php endwhile; // end of the loop. ?>

    </div>

<?php } elseif (is_product_category() && get_field('field_name') == false ) { // Added close brace

<div> Empty Test </div>
}
  • 写回答

2条回答 默认 最新

  • duanhao9176 2013-10-16 10:23
    关注

    Ok, I re-read the docs for ACF and found the following (http://www.advancedcustomfields.com/resources/how-to/how-to-get-values-from-a-taxonomy-term/)

    So I applied with some logic and now it works. Thanks for var_dump pointer as that helped me fix this.

    // vars
    $queried_object = get_queried_object(); 
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;  
    
    $is_field_name = get_field('field_name', $taxonomy . '_' . $term_id);
    
    if (is_product_category() && $is_field_name == false) { ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何解决y_true和y_predict数据类型不匹配的问题(相关搜索:机器学习)
  • ¥15 PB中矩阵文本型数据的总计问题。
  • ¥40 宿舍管理系统设计(c#)
  • ¥15 MATLAB卫星二体模型仿真
  • ¥15 怎么让数码管亮的同时让led执行流水灯代码
  • ¥20 SAP HANA SQL Script 。如何判断字段值包含某个字符串
  • ¥85 cmd批处理参数如果含有双引号,该如何传入?
  • ¥15 fx2n系列plc的自控成型机模拟
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。