Edición de publicaciones de front-end usando un formulario
3 respuestas
- votos
-
- 2011-02-21
Si deseaeditar unapublicaciónexistente,pruebemi plugin Front-end Editor .
Si desea crearpublicacionesnuevas,pruebe una deestas:
If you want to edit an existing post, try my Front-end Editor plugin.
If you want to create new posts, try one of these:
-
Gracias Scribu.Su complementoesfantástico,perono se ajusta amisnecesidades.Estoyintentandoeditar unapublicaciónexistente con unformulario.Hice unapregunta similar sobre laedición delperfil de un usuario con unformularioen lainterfaz y recibíesta respuesta: http://wordpress.stackexchange.com/questions/9775/how-to-edit-a-user-profile-on-the-front-end Estofuncionóperfectamenteparamí.Siexiste una solución similarparaeditarpublicaciones,estaríamuy agradecido.Thanks Scribu. Your plugin is fantastic, but it does not fit my need. I am trying to edit an existing post with a form. I asked a similar question about editing a user's profile with a form in the frontend and I received this response: http://wordpress.stackexchange.com/questions/9775/how-to-edit-a-user-profile-on-the-front-end This worked perfectly for me. If there is a similar solution for editing posts I would be so grateful.
- 0
- 2011-02-21
- Carson
-
¿Esposible agregarmetaboxesjunto con él?is it possible to add metaboxes along with it??
- 0
- 2011-06-17
- nickfrancis.me
-
@nickfancis.me usa comentariosparaestetipo de cosas,¡paraesoestán ahí!@nickfancis.me use comments for this sort of thing - that's what they're there for!
- 0
- 2011-06-17
- TheDeadMedic
-
@nickfrancis.me Losmetaboxes sonestrictamenteparaelbackend.¿Quizáste refieres a los widgets?@nickfrancis.me Metaboxes are strictly for the backend. Maybe you mean widgets?
- 0
- 2011-06-17
- scribu
-
- 2013-07-15
Aquí hay una soluciónbásicapara actualizar unapublicación/página. Agregué una demostración rápida demetacampospersonalizados. Estoesbastantebásico,pero leindicará la dirección de laedición depublicaciones sin complementosen elfront-end. Estonoesmuyflexible,peropuede agregar lo quenecesite.
Agregaeste código atubucle:
<form id="post" class="post-edit front-end-form" method="post" enctype="multipart/form-data"> <input type="hidden" name="post_id" value="<?php the_ID(); ?>" /> <?php wp_nonce_field( 'update_post_'. get_the_ID(), 'update_post_nonce' ); ?> <p><label for="post_title">Title</label> <input type="text" id="post_title" name="post_title" value="<?php echo $post->post_title; ?>" /></p> <p><?php wp_editor( $post->post_content, 'postcontent' ); ?></p> <p><label for="post_title">Test</label> <?php $value = get_post_meta(get_the_ID(), 'edit_test', true); ?> <input type="text" id="edit_test" name="edit_test" value="<?php echo $value; ?>" /></p> <p><label for="post_title">Test 2</label> <?php $value = get_post_meta(get_the_ID(), 'edit_test2', true); ?> <input type="text" id="edit_test2" name="edit_test2" value="<?php echo $value; ?>" /></p> <input type="submit" id="submit" value="Update" /> </form>
Luego,agregueeste códigoen laparte superior de lapáginaparaprocesarelformulario:
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && ! empty($_POST['post_id']) && ! empty($_POST['post_title']) && isset($_POST['update_post_nonce']) && isset($_POST['postcontent']) ) { $post_id = $_POST['post_id']; $post_type = get_post_type($post_id); $capability = ( 'page' == $post_type ) ? 'edit_page' : 'edit_post'; if ( current_user_can($capability, $post_id) && wp_verify_nonce( $_POST['update_post_nonce'], 'update_post_'. $post_id ) ) { $post = array( 'ID' => esc_sql($post_id), 'post_content' => esc_sql($_POST['postcontent']), 'post_title' => esc_sql($_POST['post_title']) ); wp_update_post($post); if ( isset($_POST['edit_test']) ) update_post_meta($post_id, 'edit_test', esc_sql($_POST['edit_test']) ); if ( isset($_POST['edit_test2']) ) update_post_meta($post_id, 'edit_test2', esc_sql($_POST['edit_test2']) ); } else { wp_die("You can't do that"); } }
Here is a basic solutions for updating a post/page. I added a quick demo of custom meta fields. This is pretty basic, but will point you in the direction of plugin-less editing of posts on the front-end. This isn't super flexible, but you can add whatever you need to it.
Add this code into your loop:
<form id="post" class="post-edit front-end-form" method="post" enctype="multipart/form-data"> <input type="hidden" name="post_id" value="<?php the_ID(); ?>" /> <?php wp_nonce_field( 'update_post_'. get_the_ID(), 'update_post_nonce' ); ?> <p><label for="post_title">Title</label> <input type="text" id="post_title" name="post_title" value="<?php echo $post->post_title; ?>" /></p> <p><?php wp_editor( $post->post_content, 'postcontent' ); ?></p> <p><label for="post_title">Test</label> <?php $value = get_post_meta(get_the_ID(), 'edit_test', true); ?> <input type="text" id="edit_test" name="edit_test" value="<?php echo $value; ?>" /></p> <p><label for="post_title">Test 2</label> <?php $value = get_post_meta(get_the_ID(), 'edit_test2', true); ?> <input type="text" id="edit_test2" name="edit_test2" value="<?php echo $value; ?>" /></p> <input type="submit" id="submit" value="Update" /> </form>
Then add this code at the top of the page to process the form:
if ( 'POST' == $_SERVER['REQUEST_METHOD'] && ! empty($_POST['post_id']) && ! empty($_POST['post_title']) && isset($_POST['update_post_nonce']) && isset($_POST['postcontent']) ) { $post_id = $_POST['post_id']; $post_type = get_post_type($post_id); $capability = ( 'page' == $post_type ) ? 'edit_page' : 'edit_post'; if ( current_user_can($capability, $post_id) && wp_verify_nonce( $_POST['update_post_nonce'], 'update_post_'. $post_id ) ) { $post = array( 'ID' => esc_sql($post_id), 'post_content' => esc_sql($_POST['postcontent']), 'post_title' => esc_sql($_POST['post_title']) ); wp_update_post($post); if ( isset($_POST['edit_test']) ) update_post_meta($post_id, 'edit_test', esc_sql($_POST['edit_test']) ); if ( isset($_POST['edit_test2']) ) update_post_meta($post_id, 'edit_test2', esc_sql($_POST['edit_test2']) ); } else { wp_die("You can't do that"); } }
-
Agreguéesc_sql ().Seme acaba de ocurrir que deberíaevitar que los datos seenvíen desde unformulariopúblico (semipúblico) comoese.I added esc_sql(). It just occurred to me that you should escape data being submitted from a public (semi-public) form like that.
- 0
- 2013-07-16
- Jake
-
Gracias,peromi formulario soloestá disponiblepara administradores.Detodosmodos,será útil si alguna vez utilizoesteformularioparapublicaciónpública.Thanks, But my form is only available for Admin. Anyway it will be helpful if ever I use this form for public posting.
- 1
- 2013-07-17
- user1983017
-
- 2013-07-14
Laformamás sencilla sería utilizar algo como Ninja Forms con la siguienteextensiónpaga:
http://wpninjas.com/downloads/front-end-posting/
Tambiénpuede codificaresto ustedmismo. Básicamente,creará unformulario y luego usará
wp_insert_post()
para crear unapublicación completa.Unformulario demuestra:
<form action="" id="primaryPostForm" method="POST"> <fieldset> <label for="postTitle"><?php _e('Post Title:', 'framework') ?></label> <input type="text" name="postTitle" id="postTitle" class="required" /> </fieldset> <fieldset> <label for="postContent"><?php _e('Post Content:', 'framework') ?></label> <textarea name="postContent" id="postContent" rows="8" cols="30" class="required"></textarea> </fieldset> <fieldset> <input type="hidden" name="submitted" id="submitted" value="true" /> <button type="submit"><?php _e('Add Post', 'framework') ?></button> </fieldset>
y luego,alenviarlo,guardaríaelproceso con algo como:
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) { if ( trim( $_POST['postTitle'] ) === '' ) { $postTitleError = 'Please enter a title.'; $hasError = true; } $post_information = array( 'post_title' => wp_strip_all_tags( $_POST['postTitle'] ), 'post_content' => $_POST['postContent'], 'post_type' => 'post', 'post_status' => 'pending' ); wp_insert_post( $post_information ); }
El código completo yeltutorial son de: http://wp.tutsplus.com/tutoriales/codificación-creativa/publicación-mediante-la-inserción-de-front-end/
The easiest way would be to use something like Ninja Forms with the following paid extension:
http://wpninjas.com/downloads/front-end-posting/
You could also code this yourself. Essentially you'll create a form, and then use
wp_insert_post()
to create a full post.A sample form:
<form action="" id="primaryPostForm" method="POST"> <fieldset> <label for="postTitle"><?php _e('Post Title:', 'framework') ?></label> <input type="text" name="postTitle" id="postTitle" class="required" /> </fieldset> <fieldset> <label for="postContent"><?php _e('Post Content:', 'framework') ?></label> <textarea name="postContent" id="postContent" rows="8" cols="30" class="required"></textarea> </fieldset> <fieldset> <input type="hidden" name="submitted" id="submitted" value="true" /> <button type="submit"><?php _e('Add Post', 'framework') ?></button> </fieldset>
and then on submit, you'd save process it something like:
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) { if ( trim( $_POST['postTitle'] ) === '' ) { $postTitleError = 'Please enter a title.'; $hasError = true; } $post_information = array( 'post_title' => wp_strip_all_tags( $_POST['postTitle'] ), 'post_content' => $_POST['postContent'], 'post_type' => 'post', 'post_status' => 'pending' ); wp_insert_post( $post_information ); }
The full code and tutorial is from: http://wp.tutsplus.com/tutorials/creative-coding/posting-via-the-front-end-inserting/
-
Solo quiero actualizar (editarexistente) lapublicación/página,noinsertar.I Just want to update (edit existing) the post/page, not insert.
- 0
- 2013-07-14
- user1983017
-
Entonces,¿por quénoprobarelplugin "Front End Editor" de Scribu yamencionado?Then why not try the already-referenced "Front End Editor" plugin by Scribu?
- 0
- 2013-07-14
- helgatheviking
Tengo untipo depublicaciónpersonalizada con lasmetacajasestándar y algunos campospersonalizados.¿Cómopuedoeditar unapublicación através de unformularioen lainterfaz?