wp_insert_post let users post to without login…broke

this question has been answered on stackoverflow.
here is a link https://stackoverflow.com/questions/4321914/wp-insert-post-with-a-form/4321975#4321975

i’m trying to let users post to my site by using the wp_insert_post() function..

<?php $postTitle = $_POST['post_title'];
    $post = $_POST['post'];
    $submit = $_POST['submit'];

    if(isset($submit)){

        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' => array(7,100)
        );

        wp_insert_post($new_post);

    }

?>

I got this hooked up to a form on a category page

<form method="post" action=""> 
<input type="text" name="post_title" size="45" id="input-title"/>

<textarea rows="5" name="post" cols="66" id="text-desc"></textarea> 


<input type="hidden" name="cat" value="7,100"/> 

<input class="subput round" type="submit" name="submit" value="Post"/>
</form>

I don’t know what id did wrong..it’s not working.
any ideas? thanks

2 Answers
2

wp_insert_post() makes use of the current user at several points, if memory serves.

So, you’d want to use wp_set_current_user() to switch that to some shared author user, and then switch it back to its original value when you’re done.

Alternatively, require users to be logged in and allow all groups to create drafts.

Leave a Comment