WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using this front end post submission form that I took from this question:


$postTitle = $_POST['post_title'];
$post = $_POST['post'];
$submit = $_POST['submit'];
$category = $_POST['cat'];


    global $user_ID;

    $new_post = array(
        'post_title' => $postTitle,
        'post_content' => $post,
        'post_status' => 'publish',
        'post_date' => date('Y-m-d H:i:s'),
        'post_author' => $user_ID,
        'post_type' => 'post',
        'post_category' => $category



<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled Document</title>

<div id="wrap">
<form action="" method="post">
<table border="1" width="200">
    <td><label for="post_title">Post Title</label></td>
    <td><input name="post_title" type="text" /></td>
    <td><label for="post">Post</label></td>
    <td><input name="post" type="text" /></td>
    <td><label for="post_category">Category</label></td>
    <td><?php wp_dropdown_categories('show_count=1&hierarchical=1&hide_empty=0'); ?></td>

<input name="submit" type="submit" value="submit" />


Now, I'm trying to add the category field:

Top of the file:

$category = $_POST['cat'];

The $post array:

 'post_category' => $category

Form part:

<?php wp_dropdown_categories('show_count=1&hierarchical=1&hide_empty=0'); ?>

The HTML for the drop down menu displays but when I select another category say, Jobs, the post is published as Uncategorized.

Any suggestions to fix this?

share|improve this question
up vote 0 down vote accepted

From the Codex:

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.

Currently you giving it a string of the category ID.


$category = array(intval($_POST['cat']));
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.