我试图从一个表中获取以下数据:
并将其输入到嵌套ACF中继器场中。我已经非常接近了,因为它创建了正确的表数量(示例中的3),每个表的正确列数。
最后一部分不太好用,它只是将最后一行数据输入到"Information“中继器中,这意味着它没有迭代行号,因此只是将其输入到第1行。
我哪里出错了(见下面的代码)?因此,对于第一个表,每个信息表对于每一列都应该有4行数据。
下面是代码:
$value = array();
$rowcount = 1;
while($row = next($rows)){
$cells = $row->find('td');
$columnsCount = count($cells);
$counter = 1;
foreach ($cells as $cell) {
$value = array(
"field_5ae088999d6fb" => array(
array("field_5ae088b79d6fc" => strip_tags($cell->innertext))
)
);
update_sub_row( array('field_5ae0882f9d6f9', $tablecounter, 'field_5b3f409de191a'), $counter, $value, $post_id );
$value = array();
$counter++;
}
$rowcount++;
}
$tablecounter++;
发布于 2018-07-17 14:36:17
关于我的字段结构如下:
Field Name Field Key Type
product_codes field_5b4d8f7246886 Repeater
- table field_5b4d8fd946888 Repeater
- information field_5b4d906246889 Repeater
- text field_5b4d907f4688a Text
下面是如何更新第一个information
行中的第一个table
update_sub_row()
:
//在这里,我们构建祖先,从最顶层开始到//字段,我们正在更新它的值。$selector = 'field_5b4d8f7246886',1,//选择product\_codes
‘字段中的第一个table
_5b4d8fd946888’,//选择所有information
行;update_sub_row( $selector,1,[ 'field_5b4d906246889‘=> [ 'field_5b4d907f4688a’=> '040-811‘,field_5b4d907f4688a’=> '040-821‘,field_5b4d907f4688a’=>‘标准尺寸光纤手柄’,'field_5b4d907f4688a‘=>’1,] );
update_sub_field()
:
//在这里,我们构建祖先,从最顶层开始到//字段,我们正在更新它的值。$selector = 'field_5b4d8f7246886',1,//选择product\_codes
‘字段中的第一个table
_5b4d8fd946888’,1,//选择第一个information
行‘字段_5b4d906246889’,//最后选择所有text
列;update_sub_field( $selector,[ 'field_5b4d907f4688a‘=>’040-811“,'field_5b4d907f4688a‘=> '040-821’,'field_5b4d907f4688a‘=>’标准尺寸光纤柄‘,'field_5b4d907f4688a’=> '1‘,] );
我希望这对你有帮助,如果你需要进一步的帮助,请告诉我。
更新
试试下面的代码:
$the_row = [
'field_5ae0882f9d6f9', $tablecounter,
'field_5b3f409de191a',
];
//$value = array();
$rowcount = 1;
foreach ( $rows as $row ) {
$cells = $row->find('td');
//$columnsCount = count($cells);
//$counter = 1;
$cols = [];
foreach ($cells as $cell) {
$value = strip_tags($cell->innertext);
$cols[] = [ 'field_5ae088b79d6fc' => $value ];
//$counter++;
}
update_sub_row( $the_row, $rowcount, [
'field_5ae088999d6fb' => $cols,
], $post_id );
$rowcount++;
}
$tablecounter++;
https://stackoverflow.com/questions/51288879
复制相似问题