【问题标题】:output table in ACF that is in a repeater fieldACF 中位于转发器字段中的输出表
【发布时间】:2018-10-02 04:21:37
【问题描述】:

我正在显示一些表格,而我的表格字段位于转发器字段中,因为我想显示 4 个表格,它们是彼此的一部分。

我正在查看代码,发现它返回了一个 4 的数组。

我看过这段代码:https://wordpress.org/plugins/advanced-custom-fields-table-field/#screenshots 但这似乎只有在表格位于普通字段而不是在转发器字段中时才有效。我无法从中获取任何信息。

我一直在尝试循环遍历中继器字段,然后运行表的代码,但这似乎不起作用,我从转储中得到的只是NULL

if( have_rows($table) ): // loop through the rows of data 
  while ( have_rows($table) ) : the_row();
    var_dump($table['information_table']) 
  endwhile; 
else : 
  // no rows found 
endif;

任何人对我如何让表格从转发器字段显示有任何提示?

谢谢。

【问题讨论】:

  • 你能发布一些你已经尝试过的代码吗?
  • 我使用了链接中发布的代码,并尝试使用:if( have_rows($table) ): // loop through the rows of data while ( have_rows($table) ) : the_row(); var_dump($table['information_table']) endwhile; else : // no rows found endif; 但我从转储中得到了 NULL
  • 你有没有打电话给get_sub_field()
  • 我也尝试过这样做,但似乎没有任何结果。

标签: php wordpress advanced-custom-fields


【解决方案1】:

repeater tables
插件作者提供了这个代码示例: 不确定您缺少什么。尝试不使用 $table 变量并仅使用字段名称。验证您使用的是正确的 sub_field 名称。仔细检查您是否已将数据保存在数据库中。看起来你应该使用 sub_field('information_table') 而不是 $table['information_table']

// check if the repeater field has rows of data
if( have_rows('repeater_field_name') ):

  // loop through the rows of data
  while ( have_rows('repeater_field_name') ) : the_row();

    // get a sub field value (table field)
    $table = sub_field('sub_field_name');

    // use the “Output Table HTML” code with $table   

  endwhile;

else :

  // no rows found

endif;

【讨论】:

    猜你喜欢
    • 2021-01-16
    • 2018-10-06
    • 1970-01-01
    • 2020-05-15
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    相关资源
    最近更新 更多