There’s an example here:
http://codex.wordpress.org/Function_Reference/wp_insert_post
// Create post object
$my_post = array(
'post_title' => 'My post',
'post_content' => 'This is my post.',
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post );
‘post_category’ takes an array so you’d want to send it one.
In your example, you don’t create an array – it’s just a string.
$categories="1,2,3,4,5";
This however is an array…
$categories = array( '1,2,3,4,5' );
So this should work:
'post_category' => $categories
For PHP arrays, check out:
http://www.w3schools.com/php/php_arrays.asp
http://us1.php.net//manual/en/language.types.array.php
Related Posts:
- How to insert category and subcategory using ‘wp_insert_post’ function?
- How To Find Out WordPress Category Table in MYSQL?
- Add custom field to Category
- Get current category details the user is currently on in category.php
- Does the ‘cat’ argument in query_posts fetch posts from subcategories as well as the given ID?
- Get Default Post Category From Settings
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- Display list of Sub-Categories and the posts they contain, within one main Category
- Create subdomains for tags and categories
- Categories – create a new separate set right after the default?
- How to get this only in small letters (lowercase)? [closed]
- How to totally get rid of Category in my blog?
- Is there a function to cause empty categories not to show in menus?
- Category Specific Archive
- How to select product category while adding new product in woocommerce? [closed]
- Is there a plugin that will completely remove the category system?
- How do I count how many top level categories there are?
- How to get the number of child categories a specific parent category has?
- Removing category base form links messes up the parent-child behavior
- display most popular tags of category?
- How to get only the last child of category slug?
- Exclude category from loop not working
- How to list only child categories?
- Want to hide some categories from the categories meta box in the post editor for the two specific user roles
- Getting categories id for all products in cart
- Show recent posts in menu?
- Cannot add / edit categories to a post anymore
- List archived posts by subcategory
- What’s the Simplest Way to Override/Rewrite the %category% Permalink Structure Tag?
- Show Different Custom Menu on Different Category Pages
- How to check category of of custom post type or not
- Set a them for all subset of category
- Show archives by year from just one category
- How to query post like normal search would do. within search.php page
- How to get the id from the custom category?
- Combining post categories and link categories?
- Category being displayed without base parmalink
- wordpress sub-category ( lowercase letters + non-latin characters ) = 404
- WordPress Get Posts from each category equally
- Unwanted Duplicate Product Categories in WooCommerce
- WP didn’t redirect to canonical category URL
- Customize WordPress widget – Product Category
- Display categories with child category separated by letter
- WP admin broken. Not saving catgories or adding categories to menu
- Set colors depending on category
- get_terms function not returning anything
- Why custom taxomony not showing when create a post?
- Getting All Post From Specific category in wpdb
- Single.php Category Post Count
- wp_list_categories with show_count, except for specific categories
- Jigoshop – only displaying 10 products
- Is there a way to only show Custom Meta Data on single posts from certain catagories
- Show the amount of posts in a tag in a specific category has
- Adding a H1 Tag to Post Tags automatically, but hide the tag? (Same for Category)
- display a widget on specific category and its sub categories
- Custom page category taxonomy 404
- How to hide category
- Show 10 Sub Categories Per Parent Category Page?
- Conditional category & tag statement
- How to remove the category from post slug
- Media (images, videos, etc.) not showing on Category page
- Listing Post Categories on Home Page
- Get posts in a subcategory of a chosen parent
- How can I only display links from a child category
- Problem with Custom Post Type Categories
- Display post thumbnail for specific category outside the loop
- PHP dynamical conditional post display
- wp_dropdown_categories initial value
- Category Template – Show Last Entry as Featured
- can I ‘combine’ categories as a menu item?
- Displaying categories in different template problem
- List taxonomy terms assigned to a post in hierarchical view
- Hide category name but show posts
- Limit categories to hierarchal depth of 2
- Count how many posts have a specified tag AND category
- Show the parent taxonomy by creating shortcode in woocommerce?
- Post List by category and under custom taxonomy
- Get_term_meta() does not work with pre_get_posts()
- Unable to add multiple categories to a post in WordPress
- How to display custom fields as table in Woocommerce
- How can I exclude a particular category from my WordPress Page 1 and Page 2?
- Balance Tags to the_content Words Length
- How to create template for children category?
- Categories and Tags Conflict after Woocommerce Installation
- how to display categories for a specific post?
- the_content() not showing full posts in category template
- Show parent category if there is no subcategory
- Add category links?
- show posts found in multiple categories via category_name query string?
- Removing categories, Comments etc from posts?
- Add html word before category
- Display last postings of 5 categories on homepage
- Problem importing categories and sub-categories
- Category that can hold only specific number of post
- How to add the sidebar in all category page
- Having Trouble With get_category_by_slug In a Custom Function
- how to ask if in two categorys inside if
- Add an Exclusive or featured tag line to article titles
- How to list out post category name and description in page
- Print child category slug nicename