php - wp_insert_post with a form -
<?php $submitted = $_post['submit']; $post-title= $_post['post_title']; $post-content= $_post['post_content']; $new_post = array( 'post_title' => '$post-title', 'post_content' => '$post-content', 'post_status' => 'publish', 'post_author' => $user_id, ); if(isset($submitted)){ wp_insert_post($new_post); } ?> <form method="post" action=" "> <input type="text" name="post_title" size="45" id="input-title"/> <textarea rows="5" name="post_content" 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 tested out form , worked fine. somereason cant seem work form. ideas?
also supposed go in action form?
thanks help.
this should work.
<?php if(isset($_post['new_post']) == '1') { $post_title = $_post['post_title']; $post_category = $_post['cat']; $post_content = $_post['post_content']; $new_post = array( 'id' => '', 'post_author' => $user->id, 'post_category' => array($post_category), 'post_content' => $post_content, 'post_title' => $post_title, 'post_status' => 'publish' ); $post_id = wp_insert_post($new_post); // redirect newly created post $post = get_post($post_id); wp_redirect($post->guid); } ?> <form method="post" action=""> <input type="text" name="post_title" size="45" id="input-title"/> <?php wp_dropdown_categories('orderby=name&hide_empty=0&exclude=1&hierarchical=1'); ?> <textarea rows="5" name="post_content" cols="66" id="text-desc"></textarea> <input type="hidden" name="new_post" value="1"/> <input class="subput round" type="submit" name="submit" value="post"/> </form>
if input name new_post , value of 0 add post. no action needed form, should keep php part on top of header.
Comments
Post a Comment