Currently you are passing on this value:
'post_category' => array('3,4,5') // This is a single string
While you should be doing this:
'post_category' => array(3,4,5) // Three separate values
Don’t forget to sanitize the POST values neither:
// Initialize categories
$post_category = array();
// Prevent "undefined variable" error notices
if (isset($_POST['vtype']))
{
// Loop over selected categories
foreach ((array) $_POST['vtype'] as $vtype)
{
// Validate vtype (only numbers allowed)
if (ctype_digit((string) $vtype))
{
// Add category
$post_category[] = (int) $vtype;
}
}
}
// Save the post with $post_category in database as you did before...
You can shorten this whole block to a oneliner as well, if you like. Just for fun:
$post_category = (isset($_POST['vtype'])) ? array_filter((array) $_POST['vtype'], 'ctype_digit') : array();
Related Posts:
- How to disable 3.1 “Admin Bar” via script for the admin user?
- Front End Post Submit Form
- How to create and work with custom data / tables (i.e., for arbitrary data)?
- How to transfer one domain to another domain without losing theme options (customizer)?
- Clearing dummy data before launch
- What are the ADVANTAGES of ORIGINAL wordpress template structure?
- Change admin bar to default:off
- Get author full name
- How to change admin bar color scheme in MP6 / WP 3.8 front end?
- Template for individual post designs
- How to export/import theme customizer settings?
- When to use esc_url, esc_html, esc_attr, and friends?
- Best practices – Should I create a child theme vs. customizing a framework theme? (such as HTML5 reset)
- Has anyone tried putting PHP ActiveRecord on WordPress?
- What is the best practice for customizing a plugin’s JavaScript/jQuery?
- How the WordPress sidebar works
- Change loop order via form or link (jquery, not URL)
- Extend walker – navigation, adding data attribute to a tag
- Set front page as static page [closed]
- How to programmatically bring back “excerpts” field in post editor in WP 3.1+
- When developing a distributable Theme, does it HAVE to be “inheritable”?
- wp_head() not inserting the default stylesheet style.css
- First completely customized theme, where should I start?
- Theme Customizer not loading
- Modify Javascript Configuration Options for Theme Customizer Colour Picker
- Best practices: Custom theme sidebar menu – hardcode or widget?
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- How to handle custom form submission?
- Best way to start becoming a wordpress developer
- Displaying theme options in css
- Removing non native customizer settings from a child theme
- How to reorganize the items returned by wp_list_comments()?
- which is the best way to customize nav-menu-template.php?
- Custom URL parameters in template files
- Where should I update_options in a theme?
- WP 3.1 upgrade breaks AutoFocus+ theme
- Users table association with users_metadata table appears broken
- Displaying recent post excerpts on static front page
- Customizer: Unique identifier that distinguishes which image upload control is uploading an image
- How to make theme elements customizable in wordpress?
- defining a folder location in order to recall it
- How to create a multiple choice radio group for a single theme option
- How to edit theme functions file to modify pagination?
- Custom form in theme template displaying internal server error upon submission
- Customizer: active_callback and sanitize_callback incompatibility?
- JavaScript stops working on selectively refreshed sections one inside the other
- “Add A Widget” button in the Customizer
- How can I make my options in an array and store theme in WP options one DB row?
- Move default page templates to sub directory
- How to get the value of input hidden html from text editor to custom page template?
- Menu jumping when calling it via PHP
- Is it possible to visually group items on the theme customizer?
- Displaying icon image for WordPress post formats, is there a cleaner way to do this?
- Custom Blocks as part of a theme
- Efficiency of wp_options vs a new table
- db converts decimal number wrong
- WooCommerce: multiple input field for multiple product variations
- Customizer – loading settings/controls/sections/panels based on a id/page id
- Database Tables in WordPress Theme
- Child Theme header1.php file not overwriting parent theme’s header1.php file
- How to have content scroll over background
- “operation successful” message
- Forms won’t submit
- Is there a WordPress boolean for “theme_customizer_active()”?
- How to clean up the theme for production?
- add shortcode support in customizer
- Woocommerce Product attribute not imported with wordpress Importer [closed]
- Why when I create a new post I found 2 record related to this post into the posts database table?
- Update Specific Key Value in Complex `wp_options` object
- pass html code to worpdress
- Can’t change theme name
- Remove/Hide a Widget on a Custom Template
- Setting a post’s category
- Link to RSS feed not clickable?
- woocommerce remove coupon link does not work
- Submitting form to PHP
- Rename a folder via HTML POST request
- Store user form submitted information in post type
- Updating the database after parsing CSV document
- Unable to delete option
- How to get php file based on URL in WordPress
- How can I customize a WordPress theme before it’s downloaded?
- HTML TO WP Theme : Submenu goes down wp_nav_menu
- Any way to permanently translate themes?
- How to share posts (and plugins) between existing site and new, separate dev/test installation?
- A Customizer checkbox control that sets the setting to “” or to “blank” and show() or hide() a color control
- Customizer API way function is_customize_preview() works only in main page?
- Support Multiple featured images
- WordPress 3.5 + Foundation 5 not working on IE9
- What hook to use for loading a custom class extension during Theme initialization?
- trying to figure out how to use more that one image upload in the same section in theme customizer
- WordPress causing all code to be displayed on line 1. Receiving multiple errors after cleaning cookies and cache
- Post thats in Two Categories, only want to display name for one
- How to pass username into form that sends data to database
- Im using a right approach to use this class inside WordPress theme?
- Permalinks problem with custom theme
- How can i move my product name & price from below thumbnail to be the rollover content in Avada & Woocommerce?
- Multiple content areas with Gutenberg – Transparent areas mid content
- Custom form that stores data in mysql database
- Putting form result in my database