Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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,,

share|improve this question
    
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 '11 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. –  toscho May 24 '11 at 23:40

1 Answer 1

up vote 4 down vote accepted

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:

<?php 
          $args=array(
                     'public'   => true,
                     '_builtin' => false
                     ); 
                $output = 'names';
                $operator = 'and';
                $post_types=get_post_types($args,$output,$operator); 

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

Your Answer

 
discard

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.