NameSilo

[Resolved] Passing numbers as array of integers

Spaceship Spaceship
Watch
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:
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.
http://codex.wordpress.org/Function_Reference/wp_insert_post#Return

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?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
don't put array in quotes when setting it.

just do:

PHP:
$mycategory = array($_POST['cat1'], $_POST['cat2']);

and then you can do the
PHP:
$my_post['post_category'] = $mycategory;

keep in mind that this'll be a multidimentional array where $my_post['post_category'][0] = whatever your cat1 was, and $my_post['post_category'][1] = whatever cat2 was. i'm not too familiar with wordpress coding so i cant tell you if thats how it should be passed or not.
 
0
•••
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back