Creating post with PHP: Categories
-
Hi!
I’m making a form on a wp page from where I’ll post posts.
My problem is that I don’t know how to get the categories from a <select name”col1″><option> Formular.Here is my code:
if(isset($_POST['Col1']) && !empty($_POST['Col1'])){ $Col1_Array = $_POST['Col1']; $a=''; foreach($Col1_Array as $selectValue){ $a= $a.$selectValue.","; } } // Create post object $my_post = array(); $my_post['post_title'] = stripslashes($_POST['titre']); $my_post['post_content'] = stripslashes($_POST['description']); $my_post['post_status'] = get_user_post_status (); $my_post['post_author'] = $current_user->ID; $my_post['post_category'] = array($a.'1'); // Insert the post into the database wp_insert_post( $my_post );
this code only post on the first category that is selected.
What can I change to make it right?
Thanks
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Creating post with PHP: Categories’ is closed to new replies.