Forums

[resolved] Passing category as array of integers (1 post)

  1. ridesign
    Member
    Posted 3 years ago #

    I am trying to pass my categories as an array of integers, but they are not appearing on my site, the posts appear with the default category only.

    $mycategory = "array(". $_POST['cat1']. ", ".$_POST['cat2']. ")";
    this prints: array(1,2)

    I am using this to create the post array, like this.
    $my_post['post_category'] = $mycategory;

    What am I doing incorrect?

    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.

    'post_category => [ array(<category id>, <...>) ] //Add some categories.

    http://codex.wordpress.org/Function_Reference/wp_insert_post#Return

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.