如何将我的循环合并到以CSV格式导出?
<?php $answers = new WP_Query(array('cat' => 25, 'order' => 'DESC')); ?>
<table width="100%" border="1" cellspacing="1" cellpadding="1">
<tr>
<td valign="top">Name</td>
<td valign="top">Submission/production title</td>
<td valign="top">Performance space</td>
</tr>
<?php if ($answers->have_posts()) : while ($answers->have_posts()) : $answers->the_post(); ?>
<tr>
<td><?php echo the_title(); ?></td>
<td><?php echo the_field('submit_submission_production_title'); ?></td>
<td><?php echo the_field('submit_performance_space'); ?></td>
</tr>
<?php endwhile; ?>
</table>
<?php endif; ?>
如何将其与fputcsv进行整合?
<?php
$list = array (
'aaa,bbb,ccc,dddd',
'123,456,789',
'"aaa","bbb"'
);
$fp = fopen('file.csv', 'w');
foreach ($list as $line) {
fputcsv($fp, split(',', $line), ',', '"');
}
fclose($fp);
?>
答案 0 :(得分:1)
首先,the_title
和the_field
*是执行 echo
的功能,您不需要{{ 1}}。
echo the_title()
假设这来自高级自定义字段。
只需构建一个数组,如:
*