I have three custom post types, each with around 5 taxonomies and 2 of the custom post types share two taxonomies.

I've just about got everything set up for posting from the front end other than the part of a dropdown to show the post_types.

As it is now front end posting works but, the urls are broken because they dont have the custom post type in them, i've searched all over and can find zero on listing custom post types... can it be done?

Regards Martin

edit: Just stumbled upon this over at codex,,

  • The codex page that i stumbled on after around three hours of looking helped heaps.. everything is working ok now. wraped the function into a select and added a variable to update the wp_posts with the correct custom post type
    – MartinJJ
    May 24, 2011 at 23:14
  • 2
    Write your working code as an answer and mark it as answer. If someone else is searching for the same problem she will never find a comment of a question without answers.
    – fuxia
    May 24, 2011 at 23:40

1 Answer 1


Sorry about that feels a bit weird answering ones own question, but here you go....

Firstly declare the variable: (customcategory)

global $userdata;

$errors = array();

$title      = trim($_POST['wpuf_post_title']);
$customcategory      = trim($_POST['customcategory']);
$content    = trim($_POST['wpuf_post_content']);
$tags       = wpuf_clean_tags($_POST['wpuf_post_tags']);
$cat        = trim($_POST['cat']);

Secondly the array for adding the post:

 if (!$errors) {
    $frontend_post = array(
            'post_title'    => $title,
            'post_content'  => $content,
            'post_status'   => $post_status,
            'post_author'   => $userdata->ID,
            'post_category'    =>    array($_POST['cat']),
            'post_type' => $customcategory,
            'tags_input'    => $tags

    $post_id = wp_insert_post($frontend_post);

and finally create the dropdrown from the get_post_types function:

                     'public'   => true,
                     '_builtin' => false
                $output = 'names';
                $operator = 'and';

          echo '<select name="customcategory">';
          foreach ($post_types  as $post_type ) {
          echo '<option value="'. $post_type.'">'. $post_type. '</option>';
}echo '</select>';
  • However it wont let me mark as an answer for another two days..
    – MartinJJ
    May 24, 2011 at 23:56
  • thanks i was looking for this exact solution +1 Martin :)
    – Xavier
    Jun 4, 2011 at 18:00
  • @Xavier Glad it helped..
    – MartinJJ
    Jun 6, 2011 at 6:56

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.