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?

1 Answer 1


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']));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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