51 Replies to “Edit and Delete posts from front end with no plugin part 2”

  1. Hello! Thanks so much for this! Seems to be working so far with some tweaks. Just noticed that your last

    </form>

    tag is placed after the footer etc.
    Thanks again, this is so helpful!

    1. 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.

      1. 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?

      1. 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!

  2. 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.

    1. 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.

    2. 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; ?>
      
      1. 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.

          1. 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++;
            	}
            }
            
          1. 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)

  3. I am having trouble adding multiple file uploads, I have added the following

    <input type="file" name="image[]" multiple />

    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?

  4. 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!!!

    1. 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!

  5. 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.

  6. 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:

    $title = $_POST['title'];
    $description = $_POST['description'];
    $excerpt = $_POST['excerpt'];
    $image = $_POST['image'];
    $tags = $_POST['tags'];
    
    $post_to_edit->post_title = stripslashes($title);
    $post_to_edit->post_content = stripslashes($description);
    $post_to_edit->post_excerpt = stripslashes($excerpt);
    $post_to_edit->post_tags = stripslashes($tags);

    Here’s my form field. The dropdown is being populated via an array, and it adds its value to the textbox just fine.

    <!-- post tags -->
    <fieldset class="app_form_content">
    <label for="tags" class="app_form_label">Location:</label>
    <SELECT id="locSelection" name="URL" class="app_form_content" onchange="this.form.tags.value=this.value">
    <OPTION selected value="">Select location...</OPTION>
    <OPTION value="ND">North Dakota</OPTION>
    <OPTION value="MN">Minnesota</OPTION>
    <OPTION value="NY">New York</OPTION>
    </SELECT>
    <input type="text" value="<?php echo stripslashes($post_to_edit->post_tags); ?>" tabindex="35" name="tags" id="tags" />
    </fieldset>

    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.

  7. 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.

      1. 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.

  8. 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.

  9. 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:&nbsp;&nbsp;</span><?php echo get_post_meta($post->ID,'guide_experience_level',true); ?><br />
                        <span style="font-weight: bold;">Training/Certification:&nbsp;&nbsp;</span><?php echo get_post_meta($post->ID,'training_certification',true); ?><br />
                        <span style="font-weight: bold;">Languages Spoken:&nbsp;&nbsp;</span><?php echo get_post_meta($post->ID,'languages',true); ?><br />
                        <span style="font-weight: bold;">Pricing Structure:&nbsp;&nbsp;</span><?php echo get_post_meta($post->ID,'rate_structure',true); ?><br />
                        <span style="font-weight: bold;">Rate:&nbsp;&nbsp;</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(); ?>
  10. 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:

    <form class="edit-listing" action="http://sherpademo.co.cc/voodoo-form/" 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>

    Aaarrrggghhh!

    1. 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.

    1. 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!

      1. 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.

  11. 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

    1. 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!

  12. 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

    1. 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

  13. 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):

     $tags = strip_tags( get_the_term_list( $post_to_edit-&gt;ID, 'post_tag', '', ', ', '' ) );
    

    and in the input-field i use $tags. For saving i use (like your script):

    wp_set_post_terms($pid, array($_POST['post_tags']),'post_tag',false);
    

    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.

    1. 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!

  14. 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

  15. 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

    1. Ciao a tutti!!!!!!!!!!!!

      This code has a serious bug.
      Any user after login, if knowing the post ID of another post can delete it or change it.

      Just change the value ID =

      (“”””””)

Leave a Reply