2016-09-27 21 views
0

輸入帶有附件的圖片ID不工作的人已知可以告訴哪裏是wp_delete_attachment不具有多個值工作

<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); 
    } 
+0

的價值你輸入將是'['。您不能在雙引號內嵌套雙引號。 – Jrod

+0

@Jrod好吧,但我',米使用[鏈接](https://github.com/avral/jquery.filer)這個輸入來自Jquery/JavaScript是否有任何其他方式來更改報價 – user6743016

+0

使用'.toString'在將其設置爲您的輸入值之前,將其放在陣列上。這會將你的數組變成逗號分隔的字符串。 – Jrod

回答

0

問題解決三江源問題@Jrod找你正確

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); 
     } 
}