1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Passing category id's as array of integers

Discussion in 'PHP' started by ridesign, Nov 23, 2008.

  1. #1
    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:
    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.
    Code (markup):
    http://codex.wordpress.org/Function_Reference/wp_insert_post#Return

    What I have done:

    $mycategory = "array(". $_POST['cat1']. ", ".$_POST['cat2']. ")";
    this prints: array(1,2)
    PHP:
    I am using this to create the post array, like this.
    $my_post['post_category'] = $mycategory;
    PHP:
    What am I doing incorrect?
     
    ridesign, Nov 23, 2008 IP
  2. rene7705

    rene7705 Peon

    Messages:
    233
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this;


    
    $my_post['post_category'] = array ( $_POST['cat1'], $_POST['cat2'] );
    
    Code (markup):
     
    rene7705, Nov 23, 2008 IP
  3. ridesign

    ridesign Peon

    Messages:
    294
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks, works perfectly
     
    ridesign, Nov 24, 2008 IP