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 is the best way to handle multiple calls to get_template_directory_uri() and similar functions?
- How to handle custom form submission?
- Why is the Links Manager visible?
- searchform.php override not working
- Best way to start becoming a wordpress developer
- Displaying theme options in css
- How to add a second stylesheet to the editor
- Removing non native customizer settings from a child theme
- How to reorganize the items returned by wp_list_comments()?
- For best DB performance should I serialize all theme options together or by type?
- which is the best way to customize nav-menu-template.php?
- Adding Custom Forms
- Custom URL parameters in template files
- Where should I update_options in a theme?
- WP 3.1 upgrade breaks AutoFocus+ theme
- WP Northwind for Theme Development?
- database interactions using OOP
- Customizer: Output default value in Customizer CSS
- Users table association with users_metadata table appears broken
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Displaying recent post excerpts on static front page
- Converting HTML Template to WordPress Theme
- Customizer: Unique identifier that distinguishes which image upload control is uploading an image
- Apply different Class for each element in a foreach()
- Conditional statement to show pagination
- How to make theme elements customizable in wordpress?
- How to create a custom template to admin dashboard
- How to change database values on theme update
- How do I Add images uploaded in the post to a default custom field
- How to add a button which saves the post then executes a function
- Limitations when modifying wp_title with a filter
- defining a folder location in order to recall it
- How to create a multiple choice radio group for a single theme option
- Fastest way to get the comment and ping total count for a post
- How to make animated intro?
- How to edit theme functions file to modify pagination?
- Form doesnt save to database
- Custom form in theme template displaying internal server error upon submission
- How to display all subpages and short by year
- Getting custom posts by post id from cutomizer text input
- Customizer: active_callback and sanitize_callback incompatibility?
- Disabling Customizer Selective Refresh shortcut icons for selected controls
- JavaScript stops working on selectively refreshed sections one inside the other
- StoreFront product pages: Turn the Short Description section into a kindred tab section [closed]
- “Add A Widget” button in the Customizer
- Zoom on custom theme without child
- How can I make my options in an array and store theme in WP options one DB row?
- Customizer: save setting/control content to post/page
- Q: How to pull data from custom table to populate zustomizer setting/control select options
- 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
- Changing a slider to a grid [closed]
- Custom Navigation build using wp_nav_menu and walker
- Compare the old get_theme_mod($name) to the new get_theme_mod($name) return value
- Using My Own Classes On Wp Unit Tests
- 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
- Databases – Submitting data from inputs to database [closed]
- Customize how a WordPress theme looks like in the Theme Selector
- Efficiency of wp_options vs a new table
- db converts decimal number wrong
- WooCommerce: multiple input field for multiple product variations
- Redirect to another page using contact form 7? [closed]
- Customizer – loading settings/controls/sections/panels based on a id/page id
- Integrate WooCommerce theme with a WordPress theme [closed]
- Widget Option is Missing
- How do you use WordPress for a website that’s not in a blog format?
- Database Tables in WordPress Theme
- Is there any tool to find lines of codes responsible to generate front-end HTML elements?
- Default Text not showing from customizer
- Child Theme header1.php file not overwriting parent theme’s header1.php file
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- How to have content scroll over background
- “operation successful” message
- WordPress Template Part in iFrame
- Underscore – Self hosted fonts
- Replace site title with logo when logo is uploaded in customizer using
- What file have I to create in my custom WordPress theme to show all the post belonging to a specific category?
- Forms won’t submit
- Is there a WordPress boolean for “theme_customizer_active()”?
- How to make theme configurable
- Extending Twenty Eleven Theme
- How to clean up the theme for production?
- Templates without a loop, best practice?
- searchform.php doesn’t work properly
- CSS added through customizer neglects the need of a child theme?
- Customizer: get_preview_url() inside customize_save_after hook
- How to add custom meta box when you have a custom page template file
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- Valid SQL query not returning results
- add shortcode support in customizer
- Get wp_current_user_id using PHP and MySQL