PHP合并数组并通过wp_insert_post()发送
我正在尝试合并以下数组 我想要这个结果:PHP合并数组并通过wp_insert_post()发送,php,arrays,wordpress,Php,Arrays,Wordpress,我正在尝试合并以下数组 我想要这个结果: foreach( $datas as $data ) { $my_post = array( 'post_title' => $title['title_value'], 'post_status' => 'pending', 'post_type' => $type['type_value'], 'post_author' => $au
foreach( $datas as $data ) {
$my_post = array(
'post_title' => $title['title_value'],
'post_status' => 'pending',
'post_type' => $type['type_value'],
'post_author' => $author['author_value'],
);
wp_insert_post( $my_post );
}
$title = title1,title2,,title4,title5 // 5 datas separated with coma
$type = type1,type2,type3,type4,, // 5 datas separated with coma
$author = ,author2,author3,author4,author5 // 5 datas separated with coma
$datas = array(
'title' => explode( ",", $title ),
'type' => explode( ",", $type ),
'author' => explode( ",", $author ),
);
foreach( $datas as $data ) {
// foreach( $data as $d ) {
// }
}
我的数据:
foreach( $datas as $data ) {
$my_post = array(
'post_title' => $title['title_value'],
'post_status' => 'pending',
'post_type' => $type['type_value'],
'post_author' => $author['author_value'],
);
wp_insert_post( $my_post );
}
$title = title1,title2,,title4,title5 // 5 datas separated with coma
$type = type1,type2,type3,type4,, // 5 datas separated with coma
$author = ,author2,author3,author4,author5 // 5 datas separated with coma
$datas = array(
'title' => explode( ",", $title ),
'type' => explode( ",", $type ),
'author' => explode( ",", $author ),
);
foreach( $datas as $data ) {
// foreach( $data as $d ) {
// }
}
我所做的:
foreach( $datas as $data ) {
$my_post = array(
'post_title' => $title['title_value'],
'post_status' => 'pending',
'post_type' => $type['type_value'],
'post_author' => $author['author_value'],
);
wp_insert_post( $my_post );
}
$title = title1,title2,,title4,title5 // 5 datas separated with coma
$type = type1,type2,type3,type4,, // 5 datas separated with coma
$author = ,author2,author3,author4,author5 // 5 datas separated with coma
$datas = array(
'title' => explode( ",", $title ),
'type' => explode( ",", $type ),
'author' => explode( ",", $author ),
);
foreach( $datas as $data ) {
// foreach( $data as $d ) {
// }
}
有人知道怎么做吗?
希望你能理解这个问题。提前感谢。如果您的所有数据(标题、类型和作者)都具有相同的数据计数,您可以使用这种方法
$title\u数组=分解(',',$title);
$type_数组=分解(',',$type);
$author_数组=分解(',',$author);
如果(计数($title_数组)>0)
{
foreach($title\u数组作为$title\u索引=>$title\u值)
{
$my_post=数组(
“post_title”=>$title_值,
“post_状态”=>“挂起”,
“post\u type”=>$type\u数组[$title\u index],
“post_author'=>$author_数组[$title_index],
);
wp_insert_post($my_post);
}
}
如果您的所有数据(标题、类型和作者)具有相同的数据计数,则可以使用这种方法
$title\u数组=分解(',',$title);
$type_数组=分解(',',$type);
$author_数组=分解(',',$author);
如果(计数($title_数组)>0)
{
foreach($title\u数组作为$title\u索引=>$title\u值)
{
$my_post=数组(
“post_title”=>$title_值,
“post_状态”=>“挂起”,
“post\u type”=>$type\u数组[$title\u index],
“post_author'=>$author_数组[$title_index],
);
wp_insert_post($my_post);
}
}
谢谢。很好,谢谢。工作很好。