我试图使用php/wordpress导出csv,我在Which循环中有以下数组,它显示用户的“名称”
Array
(
[0] => Meck
)
Array
(
[0] => Bisk
)
...与此类似,我收到的电子邮件在里面循环。
Array
(
[0] => mailto:meck@gmail.com
)
Array
(
[0] => mailto:bisk@gmail.com
)现在我想在csv中导出这些数据,但是数据显示在单个列中,而不是像下面这样的单独列。
Name Email
meck
mailto:meck@gmail.com
bisk
mailto:bisk@gmail.com这是我目前的代码
global $wpdb;
$filename = 'Student_Table_' . time() . '.csv';
$header_row = array(
'Name',
'Email',
);
$data_rows = array();
ob_end_clean ();
$fh = @fopen( 'php://output', 'w' );
header( "Content-Disposition: attachment; filename={$filename}" );
fputcsv( $fh, $header_row );
while ( $query->have_posts() ) : $query->the_post();
$email = get_post_meta( get_the_ID(), 'glow_user_email', true ); // contaning email of user
$user_lastname = get_post_meta( get_the_ID(), 'glow_user_lname', true );
$user_lastname_array = $array = explode(' ', $user_lastname); // contaning name of user
//trying to merge both arrays
$data = $user_lastname_array.",".$email;
fputcsv( $fh, $data );
endwhile;发布于 2022-04-26 13:22:57
将时间循环替换为以下内容:
while ( $query->have_posts() ) : $query->the_post();
$email = get_post_meta( get_the_ID(), 'glow_user_email', true ); // contaning email of user
$user_lastname = get_post_meta( get_the_ID(), 'glow_user_lname', true );
$data = [trim($user_lastname[0]), trim($email[0])];
fputcsv( $fh, $data, ',');
endwhile;https://stackoverflow.com/questions/72013936
复制相似问题