WP_DELETE_ATTACHING不使用多个值

时间:2016-09-27 作者:user6743016

我用的是<input> 标记,该标记存储多个附件图像ID的值,但它不起作用。

有人能告诉我问题出在哪里吗?

<input type="hidden" name="jfiler-items-exclude-imgid" value="["4602","4603"]">
if (isset($_POST[\'jfiler-items-exclude-imgid\'])) {
    $att_ids = $_POST[\'jfiler-items-exclude-imgid\'];
    $att_id = explode(\',\', $att_ids);
    foreach ($att_id as $atts_id){
        wp_delete_attachment($att_ids);
}

2 个回复
最合适的回答,由SO网友:Benoti 整理而成

$att\\u id=explode(\',\',$\\u POST[\'jfiler-items-exclude-imgid\']),将返回一个键=>值数组,因此必须编写foreach循环来处理键和值

foreach($att_ids as $key=>$att_id){
    wp_delete_attachment($att_id);
}

SO网友:user6743016

借助@Benoti解决问题

    if (isset($_POST[\'jfiler-items-exclude-imgid\'])) {
        $string = str_replace(\'"\', \'\', $_POST[\'jfiler-items-exclude-imgid\']);
        $string1 = str_replace(\'\\\\\', \'\', $string); 
        $string3 = str_replace(\'[\', \'\', $string1);
        $string4 = str_replace(\']\', \'\', $string3);
        $att_ids = explode(\',\', $string4);
        foreach($att_ids as $key=>$att_id){
                wp_delete_attachment($att_id);
            }
    }