OK people. my apology to any of you who actually waited for me to post this. there was a lot going on for me latley. trip to my country, holidays, work got crazy in the holidays, new year, camping trip for my birthday and the best part is my new iMac
. so now i can smothly write This second part of this tutorial. In the first part i showed you how to create “my-posts” page and how to delete a post. In this tutorial i will show you how to edit post from front end. There is a little more going on in this part so i will try to explain it the best way i can. note that this form works for custom taxonomies when it comes to categories and tags. so i am not sure how it will work with regular categories and tag but if there are problems we can all try to figure it out. and same as in the first part of the tutorial i will break it to sections.
before we begin just to remind you that in the first part of the tutorial there are two links that will take you to the page we are going to create now:
<div class="coupon-buts"> <form class="edit-coupon" action="http://yoursite.com/edit-post.php" method="post"> <?php /* the url of the "edit-post.php" we will create later */ ?>
remember to change the “edit-post.php” to the name of this file that we are going to create now. or you can just save this file as “edit-post.php”.
lets start:
it is always good to start with the code below that check if the user is logged in, if he is not you can direct him to a login page:
<?php if ( !is_user_logged_in()) {
wp_redirect( 'http://yoursite.com/login/' );
} else {
?>
<?php
/*
Template Name: new coupon form
*/
?>
the code below get the post ID of the post that we are going to edit and store it in $post_to_edit. that happens after we click on “Edit Post” button in the “my-posts” page.
<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "edit_post" && isset($_POST['postid'])) {
$post_to_edit = array();
$post_to_edit = get_post($_POST['postid']);
the next part is very similar to the part from voodoo tutorial “how to post from your front end”. this part runs when you submit your editing. I ADDED NOTES INSIDE THE CODE
/* these are the fields that we are editing in the form below. you have to change them to your fields and you can add as many as you need. */
$title = $_POST['title'];
$description = $_POST['description'];
$street = $_POST['street']; // CHANGE "STREET" TO YOUR FIELD NAME AND YOU CAN CHANGE "$STREET" TO WHATEVER YOU WANT
$apt = $_POST['apt']; // CHANGE "APT" TO YOUR FIELD NAME AND YOU CAN CHANGE "$APT" TO WHATEVER YOU WANT
/* this code will save the title and description into the post_to_edit array */
$post_to_edit->post_title = $title;
$post_to_edit->post_content = $description;
/* honestly i can't really remember why i added this code but it is a must */
$pid = wp_update_post($post_to_edit);
/* save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false) */
/* here you have to change the "coupon_categories" and "coupon_tags" to the name of your taxonomies */
wp_set_post_terms($pid, array($_POST['cat']),'coupons_categories',false);
wp_set_post_terms($pid, array($_POST['post_tags']),'coupons_tags',false);
//UPDATE CUSTOM FIELDS WITH THE NEW INFO
//CHANGE TO YOUR CUSTOM FIELDS AND ADD AS MANY AS YOU NEED
update_post_meta($pid, 'street', $street); // CHANGE "STREET" TO YOUR FIELD NAME AND CHANGE "$STREET" ONLY IF YOU CHANGED IT ALSO IN THE CODE ABOVE
update_post_meta($pid, 'apt', $apt); // CHANGE "APT" TO YOUR FIELD NAME AND CHANGE "$APT" ONLY IF YOU CHANGED IT ALSO IN THE CODE ABOVE
//REDIRECT USER WHERE EVER YOU WANT AFTER DONE EDITING
wp_redirect( 'www.yoursite.com/my-posts/' );
//INSERT OUR MEDIA ATTACHMENTS
// THE FIRST LINE OF THE CODE AS TO DO WITH A LITTLE JAVASCRIPT THAT I WILL EXPLAIN LATER. IT CHECKS IF WE NEED TO CHANGE THE IMAGE or not
if ($_FILES) {
if ( $_POST['change_image'] == 1) {
foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$pid);
// $newupload returns the attachment id of the file that
// was just uploaded. Do whatever you want with that now.
}
} // END THE IF STATEMENT FOR FILES
} // END THE IF STATEMENT FOR if to upload image
} // end check for errors
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
?>
Now we are going to create the form. start with a little javascript that i found on the internet. i can’t remember where i found so i can’t give a credit but thank you to who ever it is
. the form below will display a thumbnail of the image that associat with this post. next to the thumbnail there is a check box that gives the user the choice of replacing the image. what the script does is showing or hiding the form to upload new image when the check box is checked or unchecked and also gives a value of “1″ or “0″ to “change_image”. this value will later be used in the code above when a user submit the form. no need to change anything in the code.
<?php get_header(); ?>
<script language="vbscript" type="text/vbs">
function showMe (it, box) {
var vis = (box.checked) ? "visible" : "hidden";
$img = (box.checked) ? document.edit_post.change_image.value = "1" : document.edit_post.change_image.value = "0" ; // send the right value if to change image or not
document.getElementById(it).style.visibility = vis;
;
}
</script>
<body onload="showMe('image', 'c1')">
next there are few lines of code that will create the “$arg” for the wp_dropdown_categories . a dropdown list of categories when the current category assign to the post will be displayed as default. it took me a while to figure it out and that is the only way i found that works with custom taxonomies. copy and paste the code and change only the “coupons_categories” to your category taxonomy name as well as “coupons_tag” for your tags taxonomy.
<?php $post_to_edit = get_post($_POST['postid']); ?>
<?php $terms = get_the_terms($post_to_edit->ID, 'coupons_categories'); ?>
<?php $coupons_tags = strip_tags( get_the_term_list( $post_to_edit->ID, 'coupons_tags', '', ', ', '' ) ); ?>
<?php $term_name = strip_tags( get_the_term_list( $post_to_edit->ID, 'coupons_categories', '', ', ', '' ) ); ?> <!-- get the category name of this post -->
<?php $term_obj = get_term_by('name', $term_name, 'coupons_categories'); ?> <!-- get the current term object -->
<?php $term_id = $term_obj->term_id ;?> <!-- get this post's term id -->
<?php $args = array(
'selected' => $term_id,
'name' => 'cat',
'class' => 'postform',
'tab_index' => 10,
'depth' => 2,
'hierarchical' => 1,
'taxonomy' => 'coupons_categories',
'hide_empty' => false ); ?> <?php /* array for wp_dropdown_category to display with the current post category selected by default */ ?>
and now the form. note that in every “fieldset” in the value of the input field i echoed the current information of the post. so when the page loads, the current information of the fields will be shown in the input field and the user will be able to edit them. you will have to change the those “get_post_meta” values to the values of your custom fields. I ADDED NOTES INSIDE THE CODE.
<div id="content" role="main">
<div class="new-coupon-form">
<!-- EDIT COUPON FORM -->
<form id="edit_post" name="edit_post" method="post" action="" enctype="multipart/form-data">
<!-- post name -->
<fieldset name="name">
<label for="title">Business Name:</label><br />
<input type="text" id="title" value="<?php echo $post_to_edit->post_title; ?>" tabindex="5" name="title" /> <!-- TITLE FIELD. NOTHING TO CHANGE -->
</fieldset>
<!-- post Category -->
<fieldset id="category">
<label for="cat" ><?php wp_dropdown_categories( $args ); ?></label> <!-- DROP DOWN WITH THE $ARG THAT WE CREATED BEFORE -->
</fieldset>
<!-- post Content -->
<fieldset class="content">
<label for="description">Discount Description:</label><br />
<textarea id="description" tabindex="15" name="description"><?php echo $post_to_edit->post_content; ?></textarea> <!-- TEXT AREA OF CONTENT. NOTHING TO CHANGE -->
</fieldset>
<!-- images -->
<?php echo get_the_post_thumbnail( $post_to_edit->ID, array( 200, 150 ) ); ?><br /> <!-- WILL DISPLAY THE POST'S THUMBNAIL. YOU CAN CHANGE THE SIZE OF IT -->
<input type="checkbox" name="c1" onclick="showMe('image', this)" >Change Image <!-- SCRIPT CHECK IF CHANGING IMAGE OR NOT. NOTHING TO CHANGE -->
<fieldset id="image">
<label for="image">Choose Image:</label>
<input type="file" name="image" id="image" tabindex="30" value="" />
</fieldset>
<h3> business's full address: </h3>
<!-- BELOW ARE THE CUSTOM FIELDS. CHANGE THEM ADD OR REMOVE -->
<fieldset class="street">
<label for="street">Street:</label><br />
<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'street', true); ?>" id="street" tabindex="20" name="street" /> <!-- CHANGE "STREET" TO NAME OF YOUR FIELD -->
</fieldset>
<fieldset class="apt">
<label for="apt">Apt/Suit Number:</label><br />
<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'apt', true); ?>" id="apt" tabindex="20" name="apt" /> <!-- CHANGE "APT" TO NAME OF YOUR FIELD -->
</fieldset>
<!-- post tags -->
<fieldset class="tags">
<label for="post_tags">Additional Keywords (comma separated):</label><br />
<input type="text" value="<?php echo $coupons_tags; ?>" tabindex="35" name="post_tags" id="post_tags" /> <!-- POST TAGS. NOTING TO CHANGE -->
</fieldset>
<fieldset class="submit">
<input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" /> <!-- SUBMIT BUTTON -->
</fieldset>
<input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" /> <!-- DONT REMOVE OR CHANGE -->
<input type="hidden" name="action" value="edit_post" /> <!-- DONT REMOVE OR CHANGE -->
<input type="hidden" name="change_cat" value="" /> <!-- DONT REMOVE OR CHANGE -->
<input type="hidden" name="change_image" value="" /> <!-- DONT REMOVE OR CHANGE -->
<?php // wp_nonce_field( 'new-post' ); ?>
</form>
and the last part
<!-- END OF FORM --> </div><!-- .entry-content --> </div><!-- #post-## --> </div><!-- #content --> <?php get_sidebar(); ?> <?php get_footer(); ?> <?php } ?> <!-- user is logged in -->
that is the code i am using in a project i am working on. it works perfect for me. there is a lot going on in there and will probably take some time to make it work with your site. or maybe not. i tried to be as clear as i could but if you guys have any questions or comments i will be more then happy to help you. i suggest you to copy the code and paste it into your editor so things will look clear.
this is the entire code:
<?php if ( !is_user_logged_in()) {
wp_redirect( 'http://yoursite.com/login/' );
} else {
?>
<?php
/*
Template Name: new coupon form
*/
?>
<?php
if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "edit_post" && isset($_POST['postid'])) {
$post_to_edit = array();
$post_to_edit = get_post($_POST['postid']);
/* these are the fields that we are editing in the form below. you have to change them to your fields and you can add as many as you need. */
$title = $_POST['title'];
$description = $_POST['description'];
$street = $_POST['street']; // CHANGE "STREET" TO YOUR FIELD NAME AND YOU CAN CHANGE "$STREET" TO WHATEVER YOU WANT
$apt = $_POST['apt']; // CHANGE "APT" TO YOUR FIELD NAME AND YOU CAN CHANGE "$APT" TO WHATEVER YOU WANT
/* this code will save the title and description into the post_to_edit array */
$post_to_edit->post_title = $title;
$post_to_edit->post_content = $description;
/* honestly i can't really remember why i added this code but it is a must */
$pid = wp_update_post($post_to_edit);
/* save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false) */
/* here you have to change the "coupon_categories" and "coupon_tags" to the name of your taxonomies */
wp_set_post_terms($pid, array($_POST['cat']),'coupons_categories',false);
wp_set_post_terms($pid, array($_POST['post_tags']),'coupons_tags',false);
//UPDATE CUSTOM FIELDS WITH THE NEW INFO
//CHANGE TO YOUR CUSTOM FIELDS AND ADD AS MANY AS YOU NEED
update_post_meta($pid, 'street', $street); // CHANGE "STREET" TO YOUR FIELD NAME AND CHANGE "$STREET" ONLY IF YOU CHANGED IT ALSO IN THE CODE ABOVE
update_post_meta($pid, 'apt', $apt); // CHANGE "APT" TO YOUR FIELD NAME AND CHANGE "$APT" ONLY IF YOU CHANGED IT ALSO IN THE CODE ABOVE
//REDIRECT USER WHERE EVER YOU WANT AFTER DONE EDITING
wp_redirect( 'www.yoursite.com/my-posts/' );
//INSERT OUR MEDIA ATTACHMENTS
// THE FIRST LINE OF THE CODE AS TO DO WITH A LITTLE JAVASCRIPT THAT I WILL EXPLAIN LATER. IT CHECKS IF WE NEED TO CHANGE THE IMAGE or not
if ($_FILES) {
if ( $_POST['change_image'] == 1) {
foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$pid);
// $newupload returns the attachment id of the file that
// was just uploaded. Do whatever you want with that now.
}
} // END THE IF STATEMENT FOR FILES
} // END THE IF STATEMENT FOR if to upload image
} // end check for errors
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
?>
<?php get_header(); ?>
<script language="vbscript" type="text/vbs">
function showMe (it, box) {
var vis = (box.checked) ? "visible" : "hidden";
$img = (box.checked) ? document.edit_post.change_image.value = "1" : document.edit_post.change_image.value = "0" ; // send the right value if to change image or not
document.getElementById(it).style.visibility = vis;
;
}
</script>
<body onload="showMe('image', 'c1')">
<?php $post_to_edit = get_post($_POST['postid']); ?>
<?php $terms = get_the_terms($post_to_edit->ID, 'coupons_categories'); ?>
<?php $coupons_tags = strip_tags( get_the_term_list( $post_to_edit->ID, 'coupons_tags', '', ', ', '' ) ); ?>
<?php $term_name = strip_tags( get_the_term_list( $post_to_edit->ID, 'coupons_categories', '', ', ', '' ) ); ?> <!-- get the category name of this post -->
<?php $term_obj = get_term_by('name', $term_name, 'coupons_categories'); ?> <!-- get the current term object -->
<?php $term_id = $term_obj->term_id ;?> <!-- get this post's term id -->
<?php $args = array(
'selected' => $term_id,
'name' => 'cat',
'class' => 'postform',
'tab_index' => 10,
'depth' => 2,
'hierarchical' => 1,
'taxonomy' => 'coupons_categories',
'hide_empty' => false ); ?> <?php /* array for wp_dropdown_category to display with the current post category selected by default */ ?>
<div id="content" role="main">
<div class="new-coupon-form">
<!-- EDIT COUPON FORM -->
<form id="edit_post" name="edit_post" method="post" action="" enctype="multipart/form-data">
<!-- post name -->
<fieldset name="name">
<label for="title">Business Name:</label><br />
<input type="text" id="title" value="<?php echo $post_to_edit->post_title; ?>" tabindex="5" name="title" /> <!-- TITLE FIELD. NOTHING TO CHANGE -->
</fieldset>
<!-- post Category -->
<fieldset id="category">
<label for="cat" ><?php wp_dropdown_categories( $args ); ?></label> <!-- DROP DOWN WITH THE $ARG THAT WE CREATED BEFORE -->
</fieldset>
<!-- post Content -->
<fieldset class="content">
<label for="description">Discount Description:</label><br />
<textarea id="description" tabindex="15" name="description"><?php echo $post_to_edit->post_content; ?></textarea> <!-- TEXT AREA OF CONTENT. NOTHING TO CHANGE -->
</fieldset>
<!-- images -->
<?php echo get_the_post_thumbnail( $post_to_edit->ID, array( 200, 150 ) ); ?><br /> <!-- WILL DISPLAY THE POST'S THUMBNAIL. YOU CAN CHANGE THE SIZE OF IT -->
<input type="checkbox" name="c1" onclick="showMe('image', this)" >Change Image <!-- SCRIPT CHECK IF CHANGING IMAGE OR NOT. NOTHING TO CHANGE -->
<fieldset id="image">
<label for="image">Choose Image:</label>
<input type="file" name="image" id="image" tabindex="30" value="" />
</fieldset>
<h3> business's full address: </h3>
<!-- BELOW ARE THE CUSTOM FIELDS. CHANGE THEM ADD OR REMOVE -->
<fieldset class="street">
<label for="street">Street:</label><br />
<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'street', true); ?>" id="street" tabindex="20" name="street" /> <!-- CHANGE "STREET" TO NAME OF YOUR FIELD -->
</fieldset>
<fieldset class="apt">
<label for="apt">Apt/Suit Number:</label><br />
<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'apt', true); ?>" id="apt" tabindex="20" name="apt" /> <!-- CHANGE "APT" TO NAME OF YOUR FIELD -->
</fieldset>
<!-- post tags -->
<fieldset class="tags">
<label for="post_tags">Additional Keywords (comma separated):</label><br />
<input type="text" value="<?php echo $coupons_tags; ?>" tabindex="35" name="post_tags" id="post_tags" /> <!-- POST TAGS. NOTING TO CHANGE -->
</fieldset>
<fieldset class="submit">
<input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" /> <!-- SUBMIT BUTTON -->
</fieldset>
<input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" /> <!-- DONT REMOVE OR CHANGE -->
<input type="hidden" name="action" value="edit_post" /> <!-- DONT REMOVE OR CHANGE -->
<input type="hidden" name="change_cat" value="" /> <!-- DONT REMOVE OR CHANGE -->
<input type="hidden" name="change_image" value="" /> <!-- DONT REMOVE OR CHANGE -->
<?php // wp_nonce_field( 'new-post' ); ?>
</form>
<!-- END OF FORM -->
</div><!-- .entry-content -->
</div><!-- #post-## -->
</div><!-- #content -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php } ?> <!-- user is logged in -->
good luck
VoodooPress Note: This is a special guest piece. It is part 2 to this post about editing and deleting posts from the front end. And it goes hand in hand with the series we started here about posting from the front end. We want to thank fitoussi for this valuable contribution to VoodooPress!

Hello! Thanks so much for this! Seems to be working so far with some tweaks. Just noticed that your last
tag is placed after the footer etc.
Thanks again, this is so helpful!
Yep, you are correct. That should come up above the closing divs I would think. There may also be an extra closing div in there. Thanks for confirming that this works, I haveen’t had time to play with it myself yet.
Yup, it should be in line 157 just before the line that says ” end of form”. Something Probably went wrong when I copied and paste the code. Is everything works fine for you Paul?
Just a note here, somehow the entities here all got screwy… I’m getting this restored properly shortly.
Let me know if you can get it restored. If it is a problem I can just copy and paste it again.
Sheesh! lol, I think everything is fine again. All I tried to do was go in and move the closing form tag. Somehow all the <> & and ” got converted. And whenever I tried to revert to an earlier version, the same thing happened. All I did was copy the code out to notepad, search and replace the html entities for the proper characters, and put it back into your post. Sorry about the mess-up, I think everything is perfect again, I seriously hope I didn’t mess up your code!
Unfortunately, (atleast for me) the photo edit checkbox does not actually replace the image for the post, it runs the function again and adds another image to the post instead.
I ran into this when I was using this form and the previous forms in the article series. I created a pretty big post addition form with 12 custom meta boxes and 12 images, one being the thumbnail(featured). I wanted to give the author the ability to replace these images with new ones but the function above does not replace but append instead.
Still looking for help on this if anyone can assist, but Im gonna keep searching.
wow, i haven’t tried this form with multipy images yet and i am going to need it later in my project. this form working well for me for the moment because i work with only feature image and this form actually replace it (because can be only one feature image). i guess we will have to find a way to do it.
I have since found a way to return all the images for the post, then add a check box below those image thumbnails and with the regular submit button above, delete the images with the check box checked.
Id like to hear any feedback on this:
<?php $post_id = ($_POST['postid']); echo $post_id . ' = POSTID<br>'; $args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post_id ); $images = get_posts( $args ); $imagenum=0; foreach($images as $image): $imagenum++; ?> <div style="width:110px; float:left;"> <?php echo wp_get_attachment_image($image->ID, 'thumbnail'); ?><br> <?php echo $image->ID; ?> <?php echo '<input type="checkbox" name="deleteimage'.$imagenum. '" value="'.$image->ID.'" />Delete Image'; ?> </div> <?php endforeach; ?>Whoops, here is the processing part:
if (isset($_POST['submit'])) { $i = 1; while ($i < 13) { if (isset($_POST['deleteimage'.$i])) { $value = $_POST['deleteimage'.$i]; if ($value !== '') { wp_delete_attachment($value); } } $i++; } }Basically, I set my posts to have a max submission of 12 images, hence the <13. The checkboxes have a name of "deleteimage" and then an autoincrement starting at 1. It loops through those and looks to see if any are checked, then if they are, they delete them.
Now this does not truly offer a "replacement" for the image but it does allow for a better edit method on the screen as it shows you all images if you did a multiple image upload like I did.
Oh… that looks like a pretty cool way to do it. I need to get these scripts all onto my test site…. been way too busy lately. Thanks for posting that up.
I figured out a new addition to this that some may find useful. I felt that deleting images was a bit too heavy handed. Instead, I added some sql to this edit page to simply detach the image from the post.
function bwd_remove_attachment($value) { global $wpdb; mysql_query("UPDATE $wpdb->posts SET post_parent='0' WHERE ID='$value'"); } if (isset($_POST['submit'])) { $i = 1; while ($i < 13) { if (isset($_POST['deleteimage'.$i])) { $value = $_POST['deleteimage'.$i]; if ($value !== '') { bwd_remove_attachment($value); } } $i++; } }That is a cool idea too! I agree that deleting images probably isn’t necessary in all cases.
Nice job Sean. however, I am having some progress with my project and soon I will need to use multiply images replacement. I guess we can try to find a way to do it together. I will start working on it maybe tonight.
(Edited by Rev. Voodoo to put spaces between words)
@fitoussi, what happened to your spacebar?????
I am having trouble adding multiple file uploads, I have added the following
But can’t get the insert_attachment running correctly as it is expecting just one single file object not a multi-dimensional array.
Anyone else had this trouble?
To anyone needing this, found this https://gist.github.com/1737887 which shows how to add multiple file uploads easily
That’s a good find, thanks for linking it!
Hi,
Wow, I cannot tell you how much I appreciate this tutorial. If I can get it all set up and functioning properly I will definitely be buying you a beer!
Here’s my question:
1. I was wondering if you could offer some tips / guidelines for adapting this method for use with Gravity Forms? I too own the GF plugin (yay!!), and I do know how to set up a form to create a post (which is what I’m planning on doing). So, could we use Gravity Forms to create the form to edit the post, rather than custom coding it like you did above? I’m not a php developer (yet!!), but I’m learning everything I can as I go.
This is a quick summary of what we’re trying to accomplish: I’m creating a website for a pet sitter, and she wants her clients to be able to register and have an expanded profile (done!). Next, she wants her clients to be able to create “profile” pages for each of their pets. These profile pages would only be visible to the client themselves, and to Shannon (the pet sitter). The purpose is so that the client can add important information about the pet (health issues, etc.), and be able to go in and edit that information as necessary. Shannon will be able to quickly search through all of the pet profiles to find the pertinent information. So once a user logs in, they would go to their profile page (located in the front-end, not the dashboard), and click “Add a Pet” or “Edit Pet Information.” When they would click on the Add a Pet link it would just take them to the gravity form to create a new post (pet profile). But if they click “Edit Pet Information,” it would take them to a page where each of their pets are listed, and they could then click the appropriate one to edit the info.
Sorry for being so long!!!
I’ve been cruising around the Gravity Forms forums for a bit. There are a lot of cool plans in the works. One of the features they are working on for the next couple of major releases are:
1. Allowing lengthy forms to be partially filled, and returned to for completion.
2. Allowing the form to be used for editing submissions.
So, currently there is no way to edit through Gravity Forms. It can be done, but requires some pretty major work on the developer side of things from what I’m reading. However, the feature is in the works for v. 1.7, or maybe 2.0. So although there is no set date for the features, theuy are coming!
HI Lauren,
First, i love beer. draft and light
second, i like the idea of your site and you can do it all using this tutorial and the first tutorial (post from front end with no plugin) that was created by rev. voodoo.
the thing is that the main idea behind these tutorials is not to use plugins and use the code instead. i also never used the Gravity Forms plugin and so i do not know how it works and how the posts that being created by it are being saved (categories, custom fields and so on). the only thing i could suggest you is to use the 3 tutorials in this website:
1) how to post from front end – to create a front end form for a new profile for a pet.
2) edit and delete post from from end part 1 – to create “my profiles” page. this page will display all the profiles that belong to a user with “delete” and “edit” buttons.
3) edit and delete posts from front end part 2 – to be able to edit a profile from the front end.
it is not very simple if but it also not very hard to accomplish that. specially if you have some coding background. also the all 3 tutorials very similar and can work together so once you accomplish one the other 2 will be easier. this also will give you more control on you form.
try to follow the steps of the tutorial and if you have any question we can always help you with that.
Good luck.
I can not for the life of me get this to work with tags. I’m using a dropdown to populate a textbox with a state abbreviation and using that for me tag. I can add the tag fine using your other excellent tutorial. However, I can’t seem to update the tag.
Here’s what I did with the form field section near the top of the form:
Here’s my form field. The dropdown is being populated via an array, and it adds its value to the textbox just fine.
So far, the textbox isn’t populating with the current tag, nor is it updating with the new once I submit the form. What stupid thing am I missing here? Thanks in advance for any help.
I have problems with accents….
title “Barbera d’asti” is transformed “Barbera d’////Asti”… ???
thanks
$post_to_edit = stripslashes_deep($post_to_edit);
Is this fixing the issue for you? Sorry, I don’t have this set up anywhere to test.
Hey,
So I realize this tutorial is a couple months old but it has been so helpful up to this point. However, for the life of me I can’t seem to get this last part to work.
I’ve got to the point where the posts of the user who is logged in are displayed but when they click the “edit post” button it redirects fine but just doesn’t seem to bring the ‘postid’ value with it.
I’m no pro but I don’t think I changed anything to those parts of the code, if possible could you break down what the second if statement is looking for (if ‘POST’ == )etc. I feel my error must be in there.
HI there! Hopefully @fitoussi will see your comment and be able to help out. Unfortunately, this is totally outside of my skill set!
Although I’d still love to find out the answer I have gone a slightly different route for now, avoiding the redirect to the ‘edit’ page completely using jquery. Once I get it finished/working maybe I’ll post my solution if you are interested.
Cheers!
ps. If this works I owe you a beer for sure.
I’m always interested! There are a tonne of WP users out there who use this info! They are always looking for improvements!
I had great hopes that this would work for me but I’m having a devil of a time passing the post id through to the form. I’m starting to wonder how you identify that this is a custom post type.
The post is created using Gravity Forms. The edit capability is reserved for members of that membership level using Wishlist plugin.
The members do not assign categories and tags so I don’t need to make those accessible.
I already have a page that lists the entries available for that member to review. I felt that, rather than create a whole new page, I could just add the “edit post” button to those items. When I investigate the code using Firebug, I can see it is picking up the post ID for that custom post type but when I click the button, the site returns a 404 so I’m not even sure if the code that I’ve written will dredge up the content from the database.
For what it is worth, I am including my code.
Code with the edit post button (guide-portal.php)
<?php /* Template Name: Elegant Guide Portal */ ?> <?php get_header(); ?> <?php global $woo_options; ?> <div id="content" class="page col-full"> <div id="main" class="col-left"> <?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<div id="breadcrumb"><p>','</p></div>'); } ?> <div class="post"> <h1 class="title cufon"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h1> <div class="entry"> <p>Welcome to the Sherpa Oupost Guide Portal. You'll find everything you need here to manage your approved Adventures and Guide Profiles</p> </div><!-- /.entry --> <?php //return all adventures for current user $this_id = get_current_user_id(); $author_id = $this_id; $args=array( 'author' => $author_id, 'post_type' => 'adventures', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo '<h2>List of Adventures</h2>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <p style="padding-left: 20px; font-size: 16px;"><b><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></b><form class="edit-listing" action="http://sherpademo.co.cc/sherpa-edit-adventure.php" method="post"> <?php /* the url of the "sherpa-edit-adventure.php" */ ?><input type="hidden" id="postid" name="postid" value="<?php the_ID(); ?>" /> <?php /* get the post ID into "postid" and later pass it to "sherpa-edit-adventure.php" */ ?><input type="submit" value="Edit" /></form></p> <?php endwhile; } wp_reset_query(); // Restore global post data stomped by the_post(). ?> <?php //return all adventures for current user $this_id = get_current_user_id(); $author_id = $this_id; $args=array( 'author' => $author_id, 'post_type' => 'guides', 'post_status' => 'publish', 'posts_per_page' => -1, 'caller_get_posts'=> 1 ); $my_query = null; $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo '<h2>List of Your Guide Profiles</h2>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <p style="padding-left: 20px; font-size: 16px;"><b><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></b><form class="edit-listing" action="http://sherpademo.co.cc/sherpa-edit-guide.php" method="post"> <?php /* the url of the "sherpa-edit-guide.php" */ ?><input type="hidden" id="postid" name="postid" value="<?php the_ID(); ?>" /> <?php /* get the post ID into "postid" and later pass it to "sherpa-edit-guide.php" */ ?><input type="submit" value="Edit" /></form></p> <?php endwhile; } wp_reset_query(); // Restore global post data stomped by the_post(). ?> </div><!-- /.post --> </div><!-- /#main --> <?php get_sidebar(); ?> </div><!-- /#content --> <?php get_footer(); ?>Code for the edit post (sherpa edit guide) is the only one written:
<?php if ( !is_user_logged_in()) { wp_redirect( 'http://sherpademo.co.cc/wp-login.php' ); } else { ?> <?php /* Template Name: sherpa edit guide */ ?> <?php if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "edit_post" && isset($_POST['postid'])) { $post_to_edit = array(); $post_to_edit = get_post($_POST['postid']); /* these are the fields that we are editing in the form below. you have to change them to your fields and you can add as many as you need. */ $title = $_POST['title']; // Guide Profile Name $description = $_POST['description']; // Guide Bio $latitude = $_POST['woo_maps_lat']; // Latitude custom field for updating map $longitude = $_POST['woo-maps_long']; // Longitude custom field for updating map $experience = $_POST['guide_experience_level']; // Update experience level $training = $_POST['training_certification']; // Update certifications $languages = $_POST['languages']; // Update languages /* this code will save the title and description into the post_to_edit array */ $post_to_edit->post_title = $title; $post_to_edit->post_content = $description; /* honestly i can't really remember why i added this code but it is a must */ $pid = wp_update_post($post_to_edit); /* save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false) */ /* here you have to change the "coupon_categories" and "coupon_tags" to the name of your taxonomies */ // wp_set_post_terms($pid, array($_POST['cat']),'coupons_categories',false); // wp_set_post_terms($pid, array($_POST['post_tags']),'coupons_tags',false); //UPDATE CUSTOM FIELDS WITH THE NEW INFO //CHANGE TO YOUR CUSTOM FIELDS AND ADD AS MANY AS YOU NEED update_post_meta($pid, 'woo_maps_lat', $latitude); // Map latitude update_post_meta($pid, 'woo-maps_long', $longitude); // Map longitude update_post_meta($pid, 'guide_experience_level', $experience); // Guide Experience update_post_meta($pid, 'training_certification', $training); // Guide Training & Certifications update_post_meta($pid, 'languages', $languages); // Guide Languages //REDIRECT USER WHERE EVER YOU WANT AFTER DONE EDITING wp_redirect( 'sherpademo.co.cc/guide-portal/' ); } // end check for errors } // END THE IF STATEMENT THAT STARTED THE WHOLE FORM ?> <?php get_header(); ?> <?php include ( TEMPLATEPATH . '/search-form.php' ); ?> <?php $post_to_edit = get_post($_POST['postid']); ?> <div id="content" class="col-full"> <div id="main-single" class="col-left"> <div class="post"> <!-- EDIT GUIDE PROFILE --> <form id="edit_post" name="edit_post" method="post" action="" enctype="multipart/form-data"> <!-- post name --> <fieldset name="name"> <label for="title">Update Guide Profile Name:</label><br /> <input type="text" id="title" value="<?php echo $post_to_edit->post_title; ?>" tabindex="5" name="title" /> <!-- TITLE FIELD. NOTHING TO CHANGE --> </fieldset> <!-- post Content --> <fieldset class="content"> <label for="description">Update Bio:</label><br /> <textarea id="description" tabindex="15" name="description"><?php echo $post_to_edit->post_content; ?></textarea> <!-- TEXT AREA OF CONTENT. NOTHING TO CHANGE --> </fieldset> <!-- images --> <?php echo get_the_post_thumbnail( $post_to_edit->ID, array( 200, 150 ) ); ?><br /> <!-- WILL DISPLAY THE POST'S THUMBNAIL. YOU CAN CHANGE THE SIZE OF IT --> <input type="checkbox" name="c1" onclick="showMe('image', this)" > <!-- SCRIPT CHECK IF CHANGING IMAGE OR NOT. NOTHING TO CHANGE --> <fieldset id="image"> <label for="image">Choose Image:</label> <input type="file" name="image" id="image" tabindex="30" value="" /> </fieldset> <h3>Update Map Coordinates</h3> <!-- BELOW ARE THE CUSTOM FIELDS. CHANGE THEM ADD OR REMOVE --> <fieldset class="woo_maps_lat"> <label for="woo_maps_lat">Latitude:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'woo_maps_lat', true); ?>" id="woo_maps_lat" tabindex="20" name="woo_maps_lat" /> <!-- Map Latitude --> </fieldset> <fieldset class="woo_maps_long"> <label for="woo_maps_long">Longitude:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'woo_maps_long', true); ?>" id="woo_maps_long" tabindex="21" name="woo_maps_long" /> <!-- Map Longitude --> </fieldset> <h3>Update Profile Details</h3> <fieldset class="guide_experience_level"> <label for="guide_experience_level">Update Experience:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'guide_experience_level', true); ?>" id="guide_experience_level" tabindex="22" name="guide_experience_level" /> <!-- Guide Experience --> </fieldset> <fieldset class="training_certification"> <label for="training_certification">Update Certifications & Training:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'training_certification', true); ?>" id="training_certification" tabindex="23" name="training_certification" /> <!-- Guide Certifications & Training --> </fieldset> <fieldset class="languages"> <label for="languages">Update Languages:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'languages', true); ?>" id="languages" tabindex="24" name="training_certification" /> <!-- Guide Languages --> </fieldset> <fieldset class="submit"> <input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" /> <!-- SUBMIT BUTTON --> </fieldset> <input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" /> <!-- DONT REMOVE OR CHANGE --> <input type="hidden" name="action" value="edit_post" /> <!-- DONT REMOVE OR CHANGE --> <?php // wp_nonce_field( 'new-post' ); ?> </form> <!-- END OF FORM --> </div><!-- post --> </div><!-- main-single --> </div><!-- #content --> <?php get_sidebar(); ?> <?php get_footer(); ?>Sorry to seem needy. I know that it isn’t your job to write my code but I’ve given it a valiant effort for the past two days and I’m out of ideas. Rev. Voodoo, you know that I am a long time admirer of your generosity and support to the WordPress community. If you want access to the development area, send me an email and I’ll set you up as an temporary admin.
I thought it might also be helpful to look at the script that presents the custom post type for this Woo Theme (Listings)
<?php get_header(); ?> <?php include ( TEMPLATEPATH . '/search-form.php' ); ?> <?php if (have_posts()) : $count = 0; ?> <?php while (have_posts()) : the_post(); $count++; ?> <?php global $woo_options, $post; if ( isset( $woo_options['woo_single_listing_image_caption'] ) ) { $listing_image_caption = get_post_meta($post->ID,$woo_options['woo_single_listing_image_caption'],true); if ($listing_image_caption != '' && $woo_options['woo_single_listing_image_caption'] == 'price') { $listing_image_caption = number_format($listing_image_caption , 0 , '.', ','); } } else { $listing_image_caption = ''; } // End If Statement //setup features array if ( $woo_options['woo_single_listing_feature_taxonomy'] ) { $features_list = get_the_term_list( $post->ID, $woo_options['woo_single_listing_feature_taxonomy'], '' , '|' , '' ); $features_array = explode('|', $features_list); //setup similar array $similar_list = get_the_term_list( $post->ID, $woo_options['woo_single_listing_related_taxonomy'], '' , '|' , '' ); $similar_list = strip_tags($similar_list); $similar_array = explode('|', $similar_list); $similar_results = ''; foreach ($similar_array as $similar_item) { $similar_id = get_term_by( 'name', $similar_item, $woo_options['woo_single_listing_related_taxonomy'] ); $similar_results = $similar_id->slug.','; } } else { $features_array = array(); $similar_results = ''; } // End If Statement ?> <div id="content" class="col-full"> <div id="main-single" class="col-left"> <div class="post"> <h1><a href="<?php the_permalink(); ?>" class="cufon"><?php the_title(); ?></a><?php if ($listing_image_caption != '') { ?><span class="price"><?php if ($woo_options['woo_single_listing_image_caption'] == 'price') { ?><?php echo stripslashes( $woo_options['woo_single_listing_starting_at_text'] ) ?><strong><?php echo $woo_options['woo_listings_currency'].$listing_image_caption; ?></strong><?php } else { echo $listing_image_caption; } ?></span><?php } ?></h1> <div class="meta"> <ul> <?php foreach ($features_array as $feature_item) { ?> <li><?php echo $feature_item; ?></li> <?php } ?> </ul> </div> <div class="entry"> <?php the_content(); ?> <div id="trip-notes"> <h2 class="featured_label">About Your Guide</h2> <p class="adventure_date"> <span style="font-weight: bold;">Experience Level: </span><?php echo get_post_meta($post->ID,'guide_experience_level',true); ?><br /> <span style="font-weight: bold;">Training/Certification: </span><?php echo get_post_meta($post->ID,'training_certification',true); ?><br /> <span style="font-weight: bold;">Languages Spoken: </span><?php echo get_post_meta($post->ID,'languages',true); ?><br /> <span style="font-weight: bold;">Pricing Structure: </span><?php echo get_post_meta($post->ID,'rate_structure',true); ?><br /> <span style="font-weight: bold;">Rate: </span>$ <?php echo get_post_meta($post->ID,'price',true); ?><br /> </p> </div> <?php //return all adventures for current user get_author_adventures(); ?> </div> <?php edit_post_link( __('{ Edit }', 'woothemes'), '<span class="small">', '</span>' ); ?> </div> </div> <div id="sidebar-single" class="col-right"> <div id="gallery"> <h2 class="cufon"><?php echo stripslashes( $woo_options['woo_single_listing_image_gallery_title'] ) ?></h2> <?php $gallery = do_shortcode('[gallery size="thumbnail" columns="4"]'); if ($gallery) { include('includes/gallery.php'); // Photo gallery } else { // echo 'no-gallery'; } ?> </div> <?php $maps_active = get_post_meta($post->ID,'woo_maps_enable',true); ?> <?php if($maps_active == 'on') { ?> <div class="map"> <h2 class="cufon"><?php echo stripslashes( $woo_options['woo_single_listing_google_map_title'] ) ?>:</h2> <div class="map <?php if (!empty($video)) { echo 'fr'; } else { echo 'wide'; } ?>"> <?php if($maps_active == 'on'){ $mode = get_post_meta($post->ID,'woo_maps_mode',true); $streetview = get_post_meta($post->ID,'woo_maps_streetview',true); $address = get_post_meta($post->ID,'woo_maps_address',true); $long = get_post_meta($post->ID,'woo_maps_long',true); $lat = get_post_meta($post->ID,'woo_maps_lat',true); $pov = get_post_meta($post->ID,'woo_maps_pov',true); $from = get_post_meta($post->ID,'woo_maps_from',true); $to = get_post_meta($post->ID,'woo_maps_to',true); $zoom = get_post_meta($post->ID,'woo_maps_zoom',true); $type = get_post_meta($post->ID,'woo_maps_type',true); $yaw = get_post_meta($post->ID,'woo_maps_pov_yaw',true); $pitch = get_post_meta($post->ID,'woo_maps_pov_pitch',true); if(!empty($lat) OR !empty($from)){ woo_maps_single_output("mode=$mode&streetview=$streetview&address=$address&long=$long&lat=$lat&pov=$pov&from=$from&to=$to&zoom=$zoom&type=$type&yaw=$yaw&pitch=$pitch"); } } ?> </div><!-- /.map --> </div> <?php } ?> </div> <div class="fix"></div> <div class="fullwidth"> <?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<div id="breadcrumb"><p>','</p></div>'); } ?> <?php //RELATED PROPERTIES - BY LOCATION $similar_results = chop($similar_results,','); $query_args = array( 'post_type' => $post->post_type, 'post__not_in' => array($post->ID), 'tax_query' => array( array( 'taxonomy' => $woo_options['woo_single_listing_related_taxonomy'], 'field' => 'slug', 'terms' => $similar_results ) ), 'posts_per_page' => 3, 'orderby' => 'rand' ); $related_query = new WP_Query($query_args); if ($related_query->have_posts()) : $count = 0; ?> <div class="similar-listings"> <h2 class="cufon"><?php echo stripslashes( $woo_options['woo_single_listing_similar_listings_title'] ) ?></h2> <?php while ($related_query->have_posts()) : $related_query->the_post(); ?> <?php $listing_image_caption = get_post_meta($post->ID,$woo_options['woo_single_listing_image_caption'],true); if ($listing_image_caption != '' && $woo_options['woo_single_listing_image_caption'] == 'price') { $listing_image_caption = number_format($listing_image_caption , 0 , '.', ','); } ?> <div class="block"> <a href="<?php the_permalink(); ?>"> <?php // woo_image('id='.$post->ID.'&key=image&width=296&height=174&link=img'); ?> <?php if ( $post->ID > 0 ) { // If a featured image is available, use it in priority over the "image" field. if ( function_exists( 'has_post_thumbnail' ) && current_theme_supports( 'post-thumbnails' ) ) { if ( has_post_thumbnail( $post->ID ) ) { $_id = 0; $_id = get_post_thumbnail_id( $post->ID ); if ( intval( $_id ) ) { $_image = array(); $_image = wp_get_attachment_image_src( $_id, 'full' ); // $_image should have 3 indexes: url, width and height. if ( count( $_image ) ) { $_image_url = $_image[0]; woo_image('src=' . $_image_url . '&key=image&width=296&height=174&link=img'); } // End IF Statement } // End IF Statement } else { woo_image('id='.$post->ID.'&key=image&width=296&height=174&link=img'); } // End IF Statement } else { woo_image('id='.$post->ID.'&key=image&width=296&height=174&link=img'); } // End IF Statement } // End IF Statement ?> </a> <?php if ($listing_image_caption != '') { ?><span class="price"><?php if ($woo_options['woo_single_listing_image_caption'] == 'price') { ?><?php echo $woo_options['woo_listings_currency'].$listing_image_caption; ?><?php } else { echo $listing_image_caption; } ?></span><?php } ?> <h2 class="cufon"><?php the_title(); ?></h2> <?php the_excerpt(); ?> <span class="more"><a href="<?php the_permalink(); ?>"><?php _e('More Info', 'woothemes') ?></a></span> </div> <?php endwhile; ?> </div><!-- /.more-listings --> <div class="fix"></div> <?php else: endif; ?> </div><!-- /.fullwidth --> <?php $comm = $woo_options['woo_comments']; if ( ($comm == "post" || $comm == "both") ) : ?> <?php comments_template('', true); ?> <?php endif; ?> </div><!-- /#content --> <?php endwhile; ?> <?php endif; ?> <?php get_footer(); ?>Ok. I got the code to work, sort of, and I’m leaving images out of it for the time being. This is probably something that one of you with less weary eyes can easily spot but can someone please tell me why this code ONLY works with the deugging statement at the top?
<?php /* Template Name: sherpa edit guide */ ?> <?php print('<pre>'); print_r($_POST); print('</pre>'); if( isset($_POST['postid'])) { // $post_to_edit = array(); $post_to_edit = get_post($_POST['postid']); /* these are the fields that we are editing in the form below. you have to change them to your fields and you can add as many as you need. */ $title = $_POST['title']; // Guide Profile Name $description = $_POST['description']; // Guide Bio $latitude = $_POST['woo_maps_lat']; // Latitude custom field for updating map $longitude = $_POST['woo-maps_long']; // Longitude custom field for updating map $experience = $_POST['guide_experience_level']; // Update experience level $training = $_POST['training_certification']; // Update certifications $languages = $_POST['languages']; // Update languages /* this code will save the title and description into the post_to_edit array */ $post_to_edit->post_title = $title; $post_to_edit->post_content = $description; /* honestly i can't really remember why i added this code but it is a must */ $pid = wp_update_post($post_to_edit); /* save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false) */ /* here you have to change the "coupon_categories" and "coupon_tags" to the name of your taxonomies */ // wp_set_post_terms($pid, array($_POST['cat']),'coupons_categories',false); // wp_set_post_terms($pid, array($_POST['post_tags']),'coupons_tags',false); //UPDATE CUSTOM FIELDS WITH THE NEW INFO //CHANGE TO YOUR CUSTOM FIELDS AND ADD AS MANY AS YOU NEED update_post_meta($pid, 'woo_maps_lat', $latitude); // Map latitude update_post_meta($pid, 'woo-maps_long', $longitude); // Map longitude update_post_meta($pid, 'guide_experience_level', $experience); // Guide Experience update_post_meta($pid, 'training_certification', $training); // Guide Training & Certifications update_post_meta($pid, 'languages', $languages); // Guide Languages //REDIRECT USER WHERE EVER YOU WANT AFTER DONE EDITING wp_redirect( 'sherpademo.co.cc/guide-portal/' ); } // end check for errors ?> <?php get_header(); ?> <?php include ( TEMPLATEPATH . '/search-form.php' ); ?> <?php $post_to_edit = get_post($_POST['postid']); ?> <div id="content" class="col-full"> <div id="main-single" class="col-left"> <div class="post"> <!-- EDIT GUIDE PROFILE --> <form id="edit_post" name="edit_post" method="post" action="" enctype="multipart/form-data"> <!-- post name --> <fieldset name="name"> <label for="title">Update Guide Profile Name:</label><br /> <input type="text" id="title" value="<?php echo $post_to_edit->post_title; ?>" tabindex="5" name="title" /> <!-- TITLE FIELD. NOTHING TO CHANGE --> </fieldset> <!-- post Content --> <fieldset class="content"> <label for="description">Update Bio:</label><br /> <textarea id="description" tabindex="15" name="description"><?php echo $post_to_edit->post_content; ?></textarea> <!-- TEXT AREA OF CONTENT. NOTHING TO CHANGE --> </fieldset> <!-- images --> <!--<?php echo get_the_post_thumbnail( $post_to_edit->ID, array( 200, 150 ) ); ?><br /> <!-- WILL DISPLAY THE POST'S THUMBNAIL. YOU CAN CHANGE THE SIZE OF IT --> <!--<input type="checkbox" name="c1" onclick="showMe('image', this)" > <!-- SCRIPT CHECK IF CHANGING IMAGE OR NOT. NOTHING TO CHANGE --> <!--<fieldset id="image"> <label for="image">Choose Image:</label> <input type="file" name="image" id="image" tabindex="30" value="" /> </fieldset>--> <h3>Update Map Coordinates</h3> <!-- BELOW ARE THE CUSTOM FIELDS. CHANGE THEM ADD OR REMOVE --> <fieldset class="woo_maps_lat"> <label for="woo_maps_lat">Latitude:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'woo_maps_lat', true); ?>" id="woo_maps_lat" tabindex="20" name="woo_maps_lat" /> <!-- Map Latitude --> </fieldset> <fieldset class="woo_maps_long"> <label for="woo_maps_long">Longitude:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'woo_maps_long', true); ?>" id="woo_maps_long" tabindex="21" name="woo_maps_long" /> <!-- Map Longitude --> </fieldset> <h3>Update Profile Details</h3> <fieldset class="guide_experience_level"> <label for="guide_experience_level">Update Experience:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'guide_experience_level', true); ?>" id="guide_experience_level" tabindex="22" name="guide_experience_level" /> <!-- Guide Experience --> </fieldset> <fieldset class="training_certification"> <label for="training_certification">Update Certifications & Training:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'training_certification', true); ?>" id="training_certification" tabindex="23" name="training_certification" /> <!-- Guide Certifications & Training --> </fieldset> <fieldset class="languages"> <label for="languages">Update Languages:</label><br /> <input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'languages', true); ?>" id="languages" tabindex="24" name="languages" /> <!-- Guide Languages --> </fieldset> <fieldset class="submit"> <input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" /> <!-- SUBMIT BUTTON --> </fieldset> <input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" /> <!-- DONT REMOVE OR CHANGE --> <input type="hidden" name="action" value="edit_post" /> <!-- DONT REMOVE OR CHANGE --> <?php // wp_nonce_field( 'new-post' ); ?> </form> <!-- END OF FORM --> </div><!-- post --> </div><!-- main-single --> </div><!-- #content --> <?php get_sidebar(); ?> <?php get_footer(); ?>When I take out lines 7-9, it appends the originating wordpress page url to the destination and comes out with a 404
What the code is looking for without debugging code:
http://sherpademo.co.cc/voodoo-form/sherpademo.co.cc/guide-portal/
What it looks for with debugging code enabled:
http://sherpademo.co.cc/voodoo-form/
Here is the code on the form of the source document:
Aaarrrggghhh!
Hi Marj Wyatt,
i am trying to understand how the little form that you posted suppose to work, i get a little confuse. i also can’t see much since this is a “members only” area. is the form suppose to send to a different page where the edit form is? i am trying to copy and paste the code (form) that you posted into my editor but i cant get it right.
I don’t know if you can follow what is my dilemma but I posted to the wordpress forum and it seems easier to read there. Here’s the link:
http://wordpress.org/support/topic/code-only-works-with-debugging-enabled?replies=1#post-2832596
Hi,
sorry everyone but for some reason i got voodoo press emails go to my hotmail trash.
I got the problem to go away. The problem was caused by the redirect so I remarked that part of my code out. Apparently, it was working only with debugging on because using that output forced the page to work.
The way the code was written, the logic was falling through to the redirect and because I did not previously understand that I had to have the absolute path to the return page, it was appending that to the end of the source page.
Long night and quite tired but at least it is working.
Even though I went about the solution a little differently, thanks again for the inspiration, Rev Voodoo!
I’m glad you were able to get there! wp_redirect can definitely be a bit flaky to work with. In earlier posts in this series, I was working with another individual, and we were tripping over the same thing. Our forms kept choking at the redirect.
I got everything worked out and, as I mentioned before, this tutorial helped me get things started. I thought that I would post my final code here at your site so others could possibly learn from it too.
Member Portal: http://pastebin.com/p3qwvWtj
I had this code developed already for a membership site. There is a custom wp query within that returns all published posts for the logged in user so they can see, at a glance, what they have out there.
This code could be edited to perform similar queries for draft or pending posts with very few tweaks. The edit button takes them to the forms that resulted from following along with this tutorial.
Edit Adventure Custom Post: http://pastebin.com/1gZ0Yjvs
Edit Profile Custom Post: http://pastebin.com/4gNX77Cd
Hi Marj, I just freed up your post from the spam queue… not sure why it’s heading that way, possibly just because of the links. Anyway, thank you for posting your code back here! That was very cool of you, and its why I love being part of the WordPress community!
Just wanted to add my thanks Marj for posting your code, saved me a lot of head banging against wall.
Hi Guys
Thanks for the very useful tutorial, but I’m really stuck after implementing this second part, with a page not found error when I click on the edit button of the posts. I rolled everything back in case I had messed up somewhere and put in the original codes from both tutorials, changing only the essential stuff such as location of the edit-post.php file, and the name of my custom posts. However I got the same result. The posts showed up just fine, but when I click on the edit button I get a page not found error. When I make a page and assign edit-post.php as the template for that page, then view the page I get the Parse error: syntax error, unexpected ‘}’ in edit-post.php on line 167. (The last line)
Any ideas why I might be having these problems?
Thanks guys
Hey Lisa.
The same what i had, at the beginning. I think there is one “}” too much. If i count the “{” and the “}” and look, where they are used, i think i will come to the following perspective:
The second “}” in my snippet is closing the “if-logged-in-thing”. If you delete this, everything will be correct – it seems for me. I’ve tried. Maybe i’m wrong (cause it’s late in the night), but it looks like correct. The snippet is from the edit-page. With the get_header-tag, you can see, where to look and what for a “}” i mean.
...
} // end check for errors
} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM
get_header(); ?>
...
Greetings
Hey Captain of Voodoo, this tutorial is really awesome and exactly this, what i need for my CRM-Theme. Thank you very much! I’m fighting step for step to success – since 2 days (cause i ever try to find a solutions by myself, and don’t ask every little question) – but there is one thing, where i get a failure. Maybe you can help me, if you would be so nice and spend me a little bit of your time. I describe:
Adding an new post from the frontend is ok. If i write more than one fag, they get separeted. Everything fine.
If i want to edit a post, the tags get not separated… So, i use (like your script):
and in the input-field i use $tags. For saving i use (like your script):
If i change the content of the input-field (delete or add a tag), it will be saved – thats no problem. But: the words are never separated. The hole content of the field is one huge tag. And yes, i use commas of course. I’ve tried with other strings – same result. I’ve tried a lot. Other methods for geting the post_tags or for saving. Everything i’ve tried: tags not separated…
I hope so much, you have an idea for this. I would be so happy and thank you so much.
I don’t want forget to say: Your site is really deluxe! There are so much creative inputs, ideas and solutions. Thank you for all this stuff!
Greetings from Austria.
I wish I could help!! I haven’t had time to keep up with this at all – and have not used this particular bit editing form at all. It’s a reader submitted post – one which I’m quite grateful for! Unfortunately I’m working and in school full time and just don’t have much time to play with code right now! Hopefully a reader subscribed to this topic will be able to help you out! Thanks for your compliments on VoodooPress!! I try very hard to get new content on here regardless of how busy I am!
This is really really great! One thing I’m struggling with though. On my submission form I use checkboxes. How do I get the edit form to display whether or not the checkboxes are already checked?
I can pre-populate the text fields no problem with the values from the submission form but can’t get the checkboxes to work…
Any ideas??
Thanks
Luke
Hi there,
I’m hoping that with your help, I can apply what you’ve done with being able to update taxonomies with a form I’m using through Gravity Form. Have you used Gravity Form and updating a form on the front end? Basically a logged in user can see the content of a post they previously submitted, including a list of checkboxes with the associated taxonomies checked. If a new checkbox is selected and the form submitted, this taxonomy is saved to the post, however if a currently checked taxonomy is unchecked and then the form submitted, the post does not remove that taxonomy. Do you know how to accomplish this, either with Gravity Form or without? Any help would be much appreciated!
Thanks,
Christine