- Impact
- 7
Passing numbers as array of integers
I am working on my wordpress site, and am trying to pass my categories as an array of integers, but they are not appearing on my site when I use the wp_insert_post function, the posts appear with the default category only.
The wordpress site says:
http://codex.wordpress.org/Function_Reference/wp_insert_post#Return
What I have done:
I am using this to create the post array, like this.
What am I doing incorrect?
I am working on my wordpress site, and am trying to pass my categories as an array of integers, but they are not appearing on my site when I use the wp_insert_post function, the posts appear with the default category only.
The wordpress site says:
Code:
Categories need to be passed as an array of integers that match the category IDs in the database. This is the case even where only one category is assigned to the post.
Example:
'post_category => [ array(<category id>, <...>) ] //Add some categories.
What I have done:
PHP:
$mycategory = "array(". $_POST['cat1']. ", ".$_POST['cat2']. ")";
this prints: array(1,2)
I am using this to create the post array, like this.
PHP:
$my_post['post_category'] = $mycategory;
What am I doing incorrect?