Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
当只有一个WP\U insert\U post时,是否创建两个post的PHP WP?_Php_Wordpress - Fatal编程技术网

当只有一个WP\U insert\U post时,是否创建两个post的PHP WP?

当只有一个WP\U insert\U post时,是否创建两个post的PHP WP?,php,wordpress,Php,Wordpress,我有一个功能,如果管理员接受请求,可以将帖子从x日期复制到x日期。所有这些都有效。然而,在for函数中每次运行都不会得到一篇文章,而是得到了两篇文章 我使用此函数调用以下函数: $start = get_field('absence_startdate', $_POST['iPostID']); $endRepeatDate = get_field('absence_endrepeat', $_POST['iPostID']); $start = new DateTime($start); $

我有一个功能,如果管理员接受请求,可以将帖子从x日期复制到x日期。所有这些都有效。然而,在for函数中每次运行都不会得到一篇文章,而是得到了两篇文章

我使用此函数调用以下函数:

$start = get_field('absence_startdate', $_POST['iPostID']);
$endRepeatDate = get_field('absence_endrepeat', $_POST['iPostID']);

$start = new DateTime($start);
$endRepeatDate = new DateTime($endRepeatDate);
$diff = $endRepeatDate->diff($start);



case 'oddweeks':
        $this->duplicatePost(round($diff->days / 7), $_POST['iPostID'], $_POST['sRepeat']);
break;
公共函数duplicatePost($runtime,$posted,$repeat)
{
对于($increment=1;$increment post\u title;
$term=获取术语($posted,'deposition'u cat');
//复制从这里开始
$duplicate=数组(
“发布状态”=>“发布”,
“职位类型”=>“缺勤”,
“post_title”=>“[R:”.$posted.]GODKENDT-”.$title,
);
交换机($重复){
// ---------------------------------------------------------------------------------------------
“每周”案例:
$dup_start=date('Ymd',strottime($org_start.'+.$increment.'week');
$dup_end=date('Ymd',strottime($org_end.'+.$increment.'week');
打破
// ---------------------------------------------------------------------------------------------
“晚间周”案例:
如果(日期('W',标准时间($org_start.'+')($increment+1.'week'))%2==0)
{
$dup_start=date('Ymd',strottime($org_start.'+'($increment+1.'week'));
$dup_end=date('Ymd',strotime($org_end.'+')($increment+1.'week');
}
其他的
{
继续;
}       
打破
// ---------------------------------------------------------------------------------------------
“奇怪的星期”案例:
如果(日期('W',标准时间($org_start.'+'($increment+1)。'week'))%2==1)
{
$dup_start=date('Ymd',strottime($org_start.'+'($increment+1.'week'));
$dup_end=date('Ymd',strotime($org_end.'+')($increment+1.'week');
}
其他的
{
继续;
}
打破
// ---------------------------------------------------------------------------------------------
“每个月”的案例:
$dup_start=date('Ymd',strottime($org_start.'+.$increment.'month');
$dup_end=date('Ymd',strotime($org_end.'+.$increment.'month');
打破
// ---------------------------------------------------------------------------------------------
“三个月”案例:
$dup_start=date('Ymd',strotime($org_start.'+')($increment+2.'month');
$dup_end=date('Ymd',strotime($org_end.'+')($increment+2.'month');
打破
// ---------------------------------------------------------------------------------------------
“六个月”案例:
$dup_start=date('Ymd',strotime($org_start.'+')($increment+5.'month');
$dup_end=date('Ymd',strotime($org_end.'+')($increment+5.'month');
打破
// ---------------------------------------------------------------------------------------------
“每一个”案例:
$dup_start=date('Ymd',strottime($org_start.'+.$increment.'year');
$dup_end=date('Ymd',strotime($org_end.'+.$increment.'year');
打破
}
$dup=wp\U insert\U post($dup);
wp_set_post_terms($dup,$term[0]->term_id,'demission_cat');
//组织变化
更新字段(“缺勤开始日期”,$dup\U start,$dup);
更新_字段(“缺勤_结束日期”,$dup_结束,$dup);
更新字段(“缺勤开始时间”,$org\U开始时间,$dup);
更新_字段('缺勤_结束时间',$org_结束时间,$dup);
更新字段('缺勤通知',$org\U note,$dup);
更新字段('缺勤管理人',$org\U admin,$dup);
更新字段('缺勤重复',$org\U repeat,$dup);
更新_字段('缺勤_结束重复',获取_字段('缺勤_结束重复',$postid),$dup);
}
}
请看一看案例“evenweeks”和案例“oddweeks”。它们都重复了两次而不是一次。我看不到问题所在。我有一个wp\u insert\u帖子,这应该只会创建一个重复

如你所见……有两个:

只能是一个。

解决方案 替换:

从我的开关盒:

continue;

为什么? 在PHP中,出于continue的目的,switch语句被视为一个循环结构。continue的行为类似于break(在没有传递任何参数的情况下)。如果开关位于循环内,continue 2将继续执行外循环的下一次迭代

continue;
continue 2;