Formulário no Front-end com wp_insert_post
-
Estou criando uma forma de pessoas interagirem com o blog enviando um depoimento, daí estou criando um formulário no Front-end para permitir essa intera??o ent?o criei o seguinte script, porém ele n?o faz a postagem na página, poderia me ajudar?
<?php function editor_randys_errors() { ?> <style> .editor-randys-error {border:1px solid #CC0000;border-radius:5px;background-color: #FFEBE8;margin: 0 0 16px 0px;padding: 12px; } </style> <?php global $error_array; foreach($error_array as $error){ echo '<p class="editor-randys-error">' . $error . '</p>'; } }; function editor_randys_notices(){ ?> <style> .editor-randys-notice {border:1px solid #E6DB55;border-radius:5px;background-color: #FFFBCC;margin: 0 0 16px 0px;padding: 12px; } </style> <?php global $notice_array; foreach($notice_array as $notice){ echo '<p class="editor-randys-notice">' . $notice . '</p>'; } }; if ( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $POST['action'] ) && $_POST['action'] == 'post' ){ $post_title = $_POST['post_title']; $post_content = $_POST['message']; if (empty($post_title)) $error_array[]='Por favor adicione um título.'; // ??if (empty($post_content)) $error_array[]='Por favor adicione conteúdo.'; $post = array( //our wp_insert_post args 'post_title' => $post_title, 'post_content' => $post_content, 'post_status' => 'publish', 'post_type' => 'testimonial' ); $my_post_id = wp_insert_post($post); //send our post, save the resulting ID } ?> <style> #box-post label{display:inline-block;width:15%;} #box-post input{width:60%;} #box-post input[type="submit"]{margin-left:15%;width:30%;padding:7px;} #box-post textarea{ display:inline-block;width:80%;vertical-align:top;} </style> <div class="post-box"> <?php do_action( 'editor-randys-notice' ); ?> <form id="box-post" action="<?php the_permalink(); ?>" method="post"> <p><label>Título: </label><input type="text" name="post_title"></p> <p><label>Mensagem: </label><textarea name="message" id="" tabindex="1" cols="30" rows="10"></textarea></p> <input type="submit" value="<?php esc_attr_e( 'Enviar Depoimento', 'editor-randys' ); ?>"> <input type="hidden" name="action" value="post"> <?php wp_nonce_field( 'new-post' ); ?> </form> </div> <?php
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Formulário no Front-end com wp_insert_post’ is closed to new replies.