Support » Developing with WordPress » help/issue with Rest API & Categories

  • Resolved dxladner


    I finally need help. I am using the WP Rest api between two WP site. User creates a post on one website and I then push the post contents to the secondary website using the Rest API. Everything works except the categories. when I try to pass either an array of Cat ids, or object of cat ids or even a strong of ids as such “4,5,6” the secondary site only uses the LAST cat id. But if I pass in a list in my body array as such: “categories” => [4,5,6] the secondary site sets all 3. I understand that the cat id in the secondary site MUST match the ones getting sent over. so the secondary site does have cats with those ids.

    Any help would be greatly appreciated!



Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter dxladner


    NVM. find my issue. The array I was building was not getting built correctly.

    For any one in the future: to pass multiple categories through the API for creating a post, you can use an array as such:

    $finalCats = array("4","5","7", "12");
    $post_data_final = array(
                        "title"     => $title,
                        "status"    => "publish",
                        "content"   => $content,
                        "author"    => $author,
                        "categories" => $finalCats

    thanks, darren

    • This reply was modified 5 years, 3 months ago by dxladner.
    Thread Starter dxladner


    issue resvoled

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘help/issue with Rest API & Categories’ is closed to new replies.