mardi 25 juillet 2017

wp_insert_post with Custom Multiple Checkboxes

I want to select all custom meta checkboxes when insert post. I cant find any solution on google.

How can i create post with multiple checkboxes?

Thats my custom checkboxes :

<input type="checkbox" name="wpcf[ozel-alan][wpcf-fields-checkboxes-option-8fd017fd5cd1b4a61304d8a4b735b311-1][]" value"test1" />
<input type="checkbox" name="wpcf[ozel-alan][wpcf-fields-checkboxes-option-3345aac51a1d1ada9d3b6671ff80ff15-1][]" value"test2" />

This is my code for create post.

$post_id = wp_insert_post(
            array(
                'comment_status'    =>  'open',
                'ping_status'       =>  'closed',
                'post_author'       =>  $author_id,
                'post_name'     =>  $slug,
                'post_title'        =>  $title,
                'post_content'      =>  'bla bla',
                'post_status'       =>  'publish',
                'post_type'     =>  'post',
                'post_category'     =>  array(3),
                'meta_input' => array(
                    'wpcf-ozel-alan[0]' => 'test1',
                    'wpcf-ozel-alan[1]' => 'test2',
                )
            )
        );

Thanks for your helps.




Aucun commentaire:

Enregistrer un commentaire