Wordpress复选框数组

时间:2012-10-06 08:31:11

标签: php wordpress

所以我有一个metabox ...带有一系列像这样的复选框:

name="my_field[]" value="1"
name="my_field[]" value="2"
name="my_field[]" value="3"
name="my_field[]" value="4"
name="my_field[]" value="5"

当我检查帖子时,它会向我发送所有复选框,而不仅仅是选择的ONES,这就是我需要的,有没有人鼓励过这个?

// LE                           

                                可湿性粉剂内容/上传/ 2012/10 / Abstract_Brush-51610.jpeg                                                             

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/10/Abstract_Wallpapers_35.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/10/Abstract_Wallpapers_35.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/10/Abstract-Desktop-Wallpapers-Mac-Apple-Pictures.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/10/Abstract-Desktop-Wallpapers-Mac-Apple-Pictures.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/09/7.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/09/7.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/09/6.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/09/6.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/09/5.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/09/5.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/09/a6057e6bac44bc179398ed2e2d5d3a2c.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/09/a6057e6bac44bc179398ed2e2d5d3a2c.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/09/2535f67307340667d7e7228115fa517d.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/09/2535f67307340667d7e7228115fa517d.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/09/1680x1050.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/09/1680x1050.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/09/5cf4ba58c8c20201cfaac290fd247d75.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/09/5cf4ba58c8c20201cfaac290fd247d75.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/08/Gibraltar.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/08/Gibraltar.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/08/background_01.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/08/background_01.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/08/bg1.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/08/bg1.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/08/bg_21.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/08/bg_21.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/08/bg.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/08/bg.jpg'  />                            </p>

                        <p>

                                                        </p>


                        <p>
                            <label>wp-content/uploads/2012/08/bg_2.jpg</label>
                            <input type='checkbox' name='choose_from_library[]' value='wp-content/uploads/2012/08/bg_2.jpg'  />                            </p>

// LE $ _POST var_dump

    array(52) { ["_wpnonce"]=> string(10) "924c761932" ["_wp_http_referer"]=> string(53) "/scai/wp-admin/post-new.php?post_type=backgroundslide" ["user_ID"]=> string(1) "1" ["action"]=> string(8) "editpost" ["originalaction"]=> string(8) "editpost" ["post_author"]=> int(1) ["post_type"]=> string(15) "backgroundslide" ["original_post_status"]=> string(10) "auto-draft" ["referredby"]=> string(84) "wp-admin/post-new.php?post_type=backgroundslide" ["_wp_original_http_referer"]=> string(84) "wp-admin/post-new.php?post_type=backgroundslide" ["auto_draft"]=> string(1) "0" ["post_ID"]=> string(3) "167" ["autosavenonce"]=> string(10) "98077d6315" ["meta-box-order-nonce"]=> string(10) "2d068e8263" ["closedpostboxesnonce"]=> string(10) "552f6efbaa" ["post_title"]=> string(16) "dasdadadadadadad" ["samplepermalinknonce"]=> string(10) "8f1ffd40fb" ["content"]=> string(0) "" ["wp-preview"]=> string(0) "" ["hidden_post_status"]=> string(5) "draft" ["post_status"]=> string(7) "publish" ["hidden_post_password"]=> string(0) "" ["hidden_post_visibility"]=> string(6) "public" ["visibility"]=> string(6) "public" ["post_password"]=> string(0) "" ["mm"]=> string(2) "10" ["jj"]=> string(2) "06" ["aa"]=> string(4) "2012" ["hh"]=> string(2) "08" ["mn"]=> string(2) "40" ["ss"]=> string(2) "43" ["hidden_mm"]=> string(2) "10" ["cur_mm"]=> string(2) "10" ["hidden_jj"]=> string(2) "06" ["cur_jj"]=> string(2) "06" ["hidden_aa"]=> string(4) "2012" ["cur_aa"]=> string(4) "2012" ["hidden_hh"]=> string(2) "08" ["cur_hh"]=> string(2) "08" ["hidden_mn"]=> string(2) "40" ["cur_mn"]=> string(2) "40" ["original_publish"]=> string(7) "Publish" ["publish"]=> string(7) "Publish" ["post_name"]=> string(0) "" ["jw_nonce"]=> string(10) "d9cc45b5e2" ["set_for_page"]=> string(7) "Contact" ["choose_from_library"]=> array(3) { [0]=> string(89) "wp-content/uploads/2012/10/Abstract_Brush-51610.jpeg" [1]=> string(90) "wp-content/uploads/2012/10/Abstract_Wallpapers_35.jpg" [2]=> string(114) "wp-content/uploads/2012/10/Abstract-Desktop-Wallpapers-Mac-Apple-Pictures.jpg" } ["post_mime_type"]=> string(0) "" ["ID"]=> int(167) ["post_content"]=> string(0) "" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" }
    array(68) { ["_wpnonce"]=> string(10) "924c761932" ["_wp_http_referer"]=> string(53) "/scai/wp-admin/post-new.php?post_type=backgroundslide" ["user_ID"]=> string(1) "1" ["action"]=> string(8) "editpost" ["originalaction"]=> string(8) "editpost" ["post_author"]=> int(1) ["post_type"]=> string(15) "backgroundslide" ["original_post_status"]=> string(10) "auto-draft" ["referredby"]=> string(84) "wp-admin/post-new.php?post_type=backgroundslide" ["_wp_original_http_referer"]=> string(84) "wp-admin/post-new.php?post_type=backgroundslide" ["auto_draft"]=> string(1) "0" ["post_ID"]=> string(3) "167" ["autosavenonce"]=> string(10) "98077d6315" ["meta-box-order-nonce"]=> string(10) "2d068e8263" ["closedpostboxesnonce"]=> string(10) "552f6efbaa" ["post_title"]=> string(16) "dasdadadadadadad" ["samplepermalinknonce"]=> string(10) "8f1ffd40fb" ["content"]=> string(0) "" ["wp-preview"]=> string(0) "" ["hidden_post_status"]=> string(5) "draft" ["post_status"]=> string(7) "publish" ["hidden_post_password"]=> string(0) "" ["hidden_post_visibility"]=> string(6) "public" ["visibility"]=> string(6) "public" ["post_password"]=> string(0) "" ["mm"]=> string(2) "10" ["jj"]=> string(2) "06" ["aa"]=> string(4) "2012" ["hh"]=> string(2) "08" ["mn"]=> string(2) "40" ["ss"]=> string(2) "43" ["hidden_mm"]=> string(2) "10" ["cur_mm"]=> string(2) "10" ["hidden_jj"]=> string(2) "06" ["cur_jj"]=> string(2) "06" ["hidden_aa"]=> string(4) "2012" ["cur_aa"]=> string(4) "2012" ["hidden_hh"]=> string(2) "08" ["cur_hh"]=> string(2) "08" ["hidden_mn"]=> string(2) "40" ["cur_mn"]=> string(2) "40" ["original_publish"]=> string(7) "Publish" ["publish"]=> string(7) "Publish" ["post_name"]=> string(0) "" ["jw_nonce"]=> string(10) "d9cc45b5e2" ["set_for_page"]=> string(7) "Contact" ["choose_from_library"]=> array(3) { [0]=> string(89) "wp-content/uploads/2012/10/Abstract_Brush-51610.jpeg" [1]=> string(90) "wp-content/uploads/2012/10/Abstract_Wallpapers_35.jpg" [2]=> string(114) "wp-content/uploads/2012/10/Abstract-Desktop-Wallpapers-Mac-Apple-Pictures.jpg" } ["post_mime_type"]=> string(0) "" ["ID"]=> int(167) ["post_content"]=> string(0) "" ["comment_status"]=> string(6) "closed" ["ping_status"]=> string(6) "closed" ["choose_from_library_wp-content/uploads/2012/10/abstract_brush-51610.jpeg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/10/abstract_wallpapers_35.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/10/abstract-desktop-wallpapers-mac-apple-pictures.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/09/7.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/09/6.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/09/5.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/09/a6057e6bac44bc179398ed2e2d5d3a2c.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/09/2535f67307340667d7e7228115fa517d.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/09/1680x1050.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/09/5cf4ba58c8c20201cfaac290fd247d75.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/08/gibraltar.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/08/background_01.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/08/bg1.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/08/bg_21.jpg"]=> string(0) "" ["choose_from_library_wp-content/uploads/2012/08/bg.jpg"]=> string(0) "" 

["choose_from_library_wp-content/uploads/2012/08/bg_2.jpg"]=> string(0) "" }

1 个答案:

答案 0 :(得分:0)

它们都被命名为choose_from_library [],所以是的,除非你只指定发送已检查的,否则你将收到所有这些。在jquery中用以下内容过滤之前检查的框:

$('input[name="choose_from_library"]').is(':checked');

或者使用您选择的后端语言过滤服务器端。