winerate

How to Post From Your Front End With No Plugin

Lately I’ve been working on another side project. A wine rating site that we hope to launch soon. But one of the requirements for the site was that once a wine rater logged in, they should have access to a form to rate wines. I didn’t want anyone to have to fuss with the back end of WordPress. I just wanted to present them with a simple form to fill out. Let’s look into how that’s done.

The first thing you need to figure out is the details. Sketch out your form, what types of data do you need? Is it just normal post stuff (title, post, categories, keywords), or do you need more? You can use custom fields/meta boxes from the front end. You can also allow thumbnail uploads to set as the featured image, or multiple image uploads. Today we will just look at the basic stuff. Tomorrow we will add image uploads.

After you have your form all filled out you need to figure out some more details. Since the main focus of my site is going to be wine rating, I want to use the standard post as wine rating. I will also use the standard categories to present a dropdown of wine types. And I will use the normal tagging system to allow for keywords. You can follow the same setup, or you can register a new post type, and use custom taxonomies, these things would only require some simple changes in the code I’ll give you, and I’ll point them out.

Now that we have all the details figured out, we need to get into the code. I set up a simple page template first. Now since this is just another form really, I borrowed heavily from my own article here about Contact Form 7. You’ll see a few blocks of code down a setup for a simple page template, it looks like:

<?php
/*
Template Name: Wine Rating Form
*/
get_header(); ?>

        <div id="container">
            <div id="content" role="main">

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <?php if ( is_front_page() ) { ?>
                        <h2 class="entry-title"><?php the_title(); ?></h2>
                    <?php } else { ?>
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    <?php } ?>

                    <div class="form-content">
                        <?php the_content(); ?>
                        <?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
                        <?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
                    </div><!-- .entry-content -->
                </div><!-- #post-## -->

                <?php comments_template( '', true ); ?>

<?php endwhile; // end of the loop. ?>

            </div><!-- #content -->
        </div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

You’ll see that the template is the same as on the example in the previous post, except I change the name to Wine Rating Form in the header of the code. So save that as whatever you like, I called it ratewine.php. You’ll see a call to the_content on line 20. I’m going to put my new form directly under that. You can do the same, or you can delete the_content, it’s up to you. I left it in as I may decide later to add some instructions through the normal WP page interface.

You’ll also notice that on line 19, I have div class=form-content rather than the normal entry-content from twenty ten. That is just to avoid having twenty ten’s css play too much on our form. That is explained in this article as well.

Let’s add in our form now! Again looking at the article from before you can see how I like to lay out my forms. I’m going to follow the same format here:

		<!-- WINE RATING FORM -->

		<div class="wpcf7">
		<form id="new_post" name="new_post" method="post" action="" class="wpcf7-form" enctype="multipart/form-data">
			<!-- post name -->
			<fieldset name="name">
				<label for="title">Wine Name:</label>
				<input type="text" id="title" value="" tabindex="5" name="title" />
			</fieldset>

			<!-- post Category -->
			<fieldset class="category">
				<label for="cat">Type:</label>
				<?php wp_dropdown_categories( 'tab_index=10&taxonomy=category&hide_empty=0' ); ?>
			</fieldset>

			<!-- post Content -->
			<fieldset class="content">
				<label for="description">Description and Notes:</label>
				<textarea id="description" tabindex="15" name="description" cols="80" rows="10"></textarea>
			</fieldset>

			<!-- post tags -->
			<fieldset class="tags">
				<label for="post_tags">Additional Keywords (comma separated):</label>
				<input type="text" value="" tabindex="35" name="post_tags" id="post_tags" />
			</fieldset>

			<fieldset class="submit">
				<input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" />
			</fieldset>

			<input type="hidden" name="action" value="new_post" />
			<?php wp_nonce_field( 'new-post' ); ?>
		</form>
		</div> <!-- END WPCF7 -->

You’ll notice I have some tags in there that come from Contact Form 7. we wrap the form in a wpcf7 class, and apply the wpcf7-form class to the actual form. This is not required of course. I just did it because I already have css in place from this tutorial. If I apply the same classes, I can reuse the css with no edits. Keep things simple eh!

The important part is to make sure the name and ID on these inputs match up with what I have. That is because we are using standard inputs. These will save to specific values that go to your database from the block of code I’m about to give you. You will also notice the second block makes use of wp_dropdown_categories, I like the idea of giving a list of categories here, since my cats are wine types. This is one place you could swap in a custom taxonomy. And finally at the bottom you’ll notice a little use of wp_nonce_field again, just a simple verification on where the data is coming from.

So that has our form all built. If you saved it now, and then applied this template to a page you would have your post form. Depending on if you followed this tutorial before, it may or may not be styled. But the big thing you would notice is that the form doesn’t do anything! You can fill it out for sure, but the data does nothing. Let’s fix that!

Way at the top of our template, under the page template header, but above the get_header call, we are going to put some code.

if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "new_post") {

	// Do some minor form validation to make sure there is content
	if (isset ($_POST['title'])) {
		$title =  $_POST['title'];
	} else {
		echo 'Please enter the wine name';
	}
	if (isset ($_POST['description'])) {
		$description = $_POST['description'];
	} else {
		echo 'Please enter some notes';
	}

	$tags = $_POST['post_tags'];

	// ADD THE FORM INPUT TO $new_post ARRAY
	$new_post = array(
	'post_title'	=>	$title,
	'post_content'	=>	$description,
	'post_category'	=>	array($_POST['cat']),  // Usable for custom taxonomies too
	'tags_input'	=>	array($tags),
	'post_status'	=>	'publish',           // Choose: publish, preview, future, draft, etc.
	'post_type'	=>	'post'  //'post',page' or use a custom post type if you want to
	);

	//SAVE THE POST
	$pid = wp_insert_post($new_post);

             //SET OUR TAGS UP PROPERLY
	wp_set_post_tags($pid, $_POST['post_tags']);

	//REDIRECT TO THE NEW POST ON SAVE
	$link = get_permalink( $pid );
	wp_redirect( $link );

} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM

//POST THE POST YO
do_action('wp_insert_post', 'wp_insert_post');

Up at the top are some instruction to WordPress to use this as a post, and we set up new_post which is what our nonce_field verifies against. After that we do some validation. Just some basic fields we want to require. And then we set up the array which grabs the data from our form and puts it all together to insert into the WordPress database. The wp_redirect line is optional, this redirects the user to their new post once they hit submit. This works great on a wine rating site I thought, take the user right to their post. (redirect threw errors, working on it) I have update the above code again. Everything works splendidly. The redirect block of code is optional or can be edited to redirect where you would like.

I’ve tried to mark with comments in the code where custom post types and custom taxonomies can be swapped out. But that pretty well does it! With this code you can have your own front end post form.

If your form isn’t styled, just take a look at this post, it has the styling I use for Contact Form 7, which if you set up your form using the layout I did above, it will work for this form as well.

Now just save up this page template to your theme and apply it to a page, and you have a post from the front end form available to your users! You probably don’t want this available to just anyone, I keep the access restricted to authors and above on my site.

Notes For Multi Category Select:I haven’t had time to totally sort this out yet, but I’m posting it here for info.
If you replace the wp_dropdown_categories line with this:

		<?php $select_cats = wp_dropdown_categories( array( 'echo' => 0, 'taxonomy' => 'category', 'hide_empty' => 0 ) );
		$select_cats = str_replace( "name='cat' id=", "name='cat[]' multiple='multiple' id=", $select_cats );
		echo $select_cats; ?>

It will allow for multiple category select. However, something needs done with the processing code above to allow that array to be handled.

Around line 16 (of the processing code), where we set up the post tags, I have this

$post_cat = $_POST['cat'];

And then in the array, I replaced the post category line with this

'post_category' =>   $post_cat,

And that was it, I am now able to select and save multiple categories!

UPDATE: If you check out this post, the end review of this form, down at the bottom we have an update with a possible fix to get the validation working properly. If you have a chance to try the fix out and report back if it works, that would be awesome!

UPDATE(2): If you cruise around the site, and search a little, you’ll find that there are a whole variety of posts related to this frontend post form. But here is a couple valuable links – our great VoodooPress readers have been busy! One of our readers provided his technique for editing and deleting these posts from the front end. Another reader got validation working and provided us with that code! That’s a lot of cool stuff! If you have anything to add here, feel free to submit your stuff, or even ask about a guest post! We are well on our way to posting perfection!

201 thoughts on “How to Post From Your Front End With No Plugin”

  1. Thanks Voodoo all your help is very appreciated!!
    But i have a small problem with my page template, because i need add only new field, where user that log-in, can add link of its site and after i will call it with custom field in template (author post submissioni in home page). It’s possibile add it in this tutorial?
    Thanks

    1. Yeah, that’s what I was talking about above. Meta boxes are used for displaying a text box. The info that the user put in the meta box goes into your custom field. I need to set up a custom meta box for a website within the next couple days on a post from front-end form. Once I do that and test it out, I’ll be putting a new tutorial up. Probably in 2 days.

      The 3rd answer here (the short one) is how to add in the box…
      http://wordpress.stackexchange.com/questions/7453/meta-boxes-in-front-end-post-submission-form

    1. I’m sorry, I don’t quite know what you mean? If you were referring to the link above, I haven’t gone over that code too much. I just provided that link as a possible place to start. Tomorrow I will have a post on here about custom fields/meta boxes from the front end, if you are still looking for that info.

      1. Wait, I see what you are asking…. the $siteurl in the example. I would think in that situation, that person has something setup on their backend for $siteurl in functions.php. http://voodoopress.com/2011/03/adding-meta-boxes-to-your-post-screen/
        Some of that may be of help. You would need a function set up for $siteurl, so the data is collected and saved in a custom field. But yeah, I’ll cover it tomorrow if you haven’t figured it out by then.

  2. thank you so much for sharing this!

    btw, was wondering if its possible to give the user a preview page, before submitting the entry?

    1. Hmmm…. that would be pretty hard I would think…. I mean there isn’t a built in equivalent to wp_insert_post that I can think of which allows for previews, or post editing. I’m sure it’s possible, but then you are really getting into pretty much rebuilding the WP backend for the frontend…..

      1. yeah thats what i thought too.. because you’d need to save the post as a draft (so the post exists) for it to be preview, i think thats the logic behind WP’s postings…

        good stuff anyways!

  3. great tutorial, the script works like a charm!
    Only one question, what if I needed to add extra category fields in the form?
    If I just copy and paste another category fieldset, the post is saved under the category selected in the second select field. Can you help?
    Thanks in advance,
    Paolo

    1. Ya know, it’s not something I’d ever considered. My form is for wine rating….. wine can only be one type really. But it’s an interesting question. You can’t repeat dropdowns for multiple values, it’ll just keep the last value. So we need to use a multi select dropdown or something, but that’s not built in to the normal dropdown. I’ll see what I can come up with when I have time!

    2. OK, I’m half way there. Maybe someone else can help, or I’ll try again when I have more time.

      At the bottom of the post above, I added a working notes section. There I give code which allows your categories to be in a multi select field. It displays and behaves properly. However something isnt working with the processing end of the equation. I can’t get the multi cats to save and display. So once we get that part figured out, we are all set!

    1. lol! Thanks for the awesome feedback, I’m glad you found this helpful! I wish I had more time to work on it further. I mean all the functionality is there and it works great. I just want to be able to get some really cool validation working on it. If you’re handy with jquery I’m sure you can get that all sorted out. Grad school and work leave me with no time to play!

      1. Just a head’s up to everyone I’ve found that wp_set_post_tags(); is adding the tags a second time (but only does so when I have more than one tag, with only one tag there are no duplicates). When I remove it and just stick with tags_input in my wp_insert_post array, I get my tags no prob.

        1. I’d have to guess it’s something funny on your end. Quite a few people have used the above code, with no doubling of tags. That specific code separates the tags. Without it, you can apply numerous comma separated tags and they are all saved as one tag. With that code, each tag separates individually. It’s been tested a lot. I am using it on 2 sites currently. Absolutely no double tags. Let me know if you find the issue….

  4. Hi there,
    for last few days I’ve been playing with your code and I really like how you explained everything…
    I read somewhere that error checking is not doing good job. I’ve solved that checking every with just basic if =”” with jQuery (if someone needs a bit more explanation feel free to ask).

    Now actually a real question. I’ve been making front end post with some heavy visual customization so input type file is making my life a living hell. Every thing I tried to do ends up as dead-end.
    Here’s what I want to do. I want to make form to create post as “draft”(easy enough) with some custom fields(also simple) and thumbnail(working). But there is no way I can make on that page where I do front-end submit preview of that image. I’ve tried with invisible inputs, jQuery, ajax posting, php temp upload etc… and God knows what else. I can make input with preview and form to send post to wp, but those 2 together no way. Any idea, suggestion ….. actually anything is welcome about now because my brain can’t figure this out with all the frustration from last 3 days.

    Keep the great work and I hope I’ll be doing some contribution to all this in the future.

    Danko Dubajic.

    1. There’s a note at the bottom of the post now, with a possible solution to the error checking in php. But yeah, jQuery is a perfectly viable solution! That preview business though…. that’s a tough one! I’m not sure how to go about that….. I’ll search around, but if you find something please report back!! Maybe even make a guest post about it or something!

      1. I’ll post some code about that jQuery…. on monday no codes for 2 day :-).
        One thing I cant understand. This thing actually does work in wordpress backhand for logo, favicon… I even tried to copy that idea but wordpress does some nasty things there and it’s almost impossible to fully copy all the things it does. Anyways I decided to avoid that preview thingy and maybe if time lets to come back and figure that one out. Till then thanks for fast response and keep it good.

        1. Trying to grab onto WPs built in stuff from the front end seems pretty darned near impossible for some things. I had tried to bring the WYSIWYG editor over, and that was a mess. I imaging trying to hook on the uploader/preview business would be just as messy!

  5. One more thing I forgot to add…. About redirect I don’t know if you figured that one but wp_redirect actually doesn’t work if you have any sort of HTML in front of it. Like when you echo that error from form check. I really don’t understand point of that redirect if you need to use it like on line 1…

  6. Ok so it’s monday morning, and back to coding…

    So my error check looks something like this:
    First you’ll need something like this included in your header:

    <script src="” type=”text/javascript”>

    <script type="text/javascript" src="”>
    , where contact.js is some custom file that we’re add some code later on.

    in line where you start form () change this:

    into this:

    and in contact.js you should have something like this:
    function check_field(field,alerttxt,checktext){
    with (field)
    { var checkfalse = 0;
    if(field.value == “”){
    $(‘#error-message’).empty().append(alerttxt);
    field.focus();checkfalse=1;}
    if(field.value==checktext)
    { $(‘#error-message’).empty().append(alerttxt);
    field.focus();checkfalse=1;
    }
    if(checkfalse==1){return false;}else{return true;}
    }
    }

    function checkFormz(thisform)
    {
    with (thisform)
    { var error = 0;
    var siteurl = document.getElementById(‘site-url’);
    if(check_field(siteurl,”Please insert your site URL”,”Site URL”)==false){
    error = 1;
    } if(error == 0){
    return true;
    } return false;
    }
    }
    To explain some more: #error-message is some custom ‘div’ where I put my result, it should be somewhere in your form or after it and it’ll print your notification about error occurred. siteurl is changeable and site-url is ID of one of my fields inside form. This here is just simple code that check if field is empty or has some default value (in my case field already have value “Site URL” because I use show/hide that when user clicks on that field, with another jQuery function and I need to check for that too). You can use this to check something more and add as much fields as you want just by multiplying:
    var XXXXX = document.getElementById(‘XXXX’);
    if(check_field(XXXXX,”Custom error message”,”not needed but if field already have some value”)==false){
    error = 1;
    }

    Voodoo plz check my code because it’s kinda hard to see all from this small box.

    If I figure out some more thing, I’ll report back, until then c ya

    1. Wow, thanks for the fantastic post! I’ll have to play with that some. It might be better to drop giant blocks of code into a pastebin and then just give us a link. Reason being, WP comment area seems to eat up the code that you worked so hard on! As you can probably see, I’ve been hard at work switching VoodooPress (along with all my other sites) to WP 3.2. Which means a new child theme for VoodooPress. Once I get things decent, I’ll be able to play around a bit.

      1. I’ll send you one example when I’m done so you can put it whole. It’s pointless to post it in chunks in comments. Your post really helped me to start this whole thing, and although it’s really really hard to customize that whole front-end post form I’m almost done….
        Still can’t make that preview to work, and because of deadline I abandoned that idea, I’ll probably come back to that later when I clear my mind from this project, it’s been really frustrating week.
        So thx again and be good…

  7. Fantastic code sample! Thanks!

    For some reason I have to replace all tabs and spaces, cause it gives me errors.

  8. I’m actually pasting it to coda, never experienced this problem before. Any how, does the fields in the page template have to match the fields in contact form 7.

    name=”description” represents [description] in wpcf7?
    It doesn’t post to a new entry..

      1. Yeah, that’s correct. I already had all my css set up from my contact form that I used CF7 for….. so I just copied/pasted the css and reused the cf7 selectors. It can be whatever you want, as long as that is reflected in the css.

    1. Nah, description is what I chose because in my form it is supposed to be a description of the wine. You can call that whatever you want, as long as in the processing code, you assign whatever you call it to be post_content.

      1. Is it possible to have more than one field to be send in post_content? Great tutorial, I’ve been looking for this for a long time. Did you made a plugin from that? Thanks

  9. I realized later that this box eat quite a lot of my code…. currently working on making custom reCaptcha on this form. It’ll be done today probably and I’ll try to post the whole thing then and maybe even a demo of that form submit.

    1. Yeah, I did get to see your code a little better in the email I got. However all the spaces and some of the characters got converted to html entities….. so it was still hard to read. I would love to see the finished product.

  10. My form does not post to new entries, any knows reasons why?

    I was prompted that the type=”submit” and id=”submit” cant be named the same so I changed the id.
    Please help!

    1. I’ve always had the type and ID match up. I was wondering if the form not submitting has to do with your field names. I’m not sure if you changed them or not, per your previous comment. The field names can change, as long as the processing code also changes to match whatever you change things to.

      1. I actually didn’t change anything with the field names or css classes.
        My method is to try the code from its origin and then change things from that. The only thing I changed was the ID of the submit button cause of the prompt. I’m on a localhost and wp3.2 maybe I should try it on 3.1.4. Don’t really see that the wordpress version should be the problem.

        1. I wouldn’t think the version change would do anything. I haven’t had time to look into it too much, but I don’t think anything changed with wp_insert_post. My site with the form is not upgraded yet to test 3.2 (the theme isn’t compatible, and I have been to busy to apply a fix).

          1. John, are you having the exact same problem as Pierre? Only one thing I can think of, are you running Contact Form 7? One of our readers had a conflict due to that. It was simple to fix really (as long as you aren’t using CF7 and this form on the same page). I have another tutorial on VooooPress relating to CF7. In it, we stop CF7 from loading on any page where it isn’t needed.

          2. yeah, i am running contact form 7. hmm i will take a look at the tutorial about loading contact form whenever its needed. do you mind posting the link?

          3. http://vudu.me/4o
            Down towards the bottom is a bit of script to stop CF7 from loading unless on a certain page. For me it’s the contact-us page. Obviously that would change for you. It’s a good thing to use anyway, no reason to load scripts on every page when not needed!

  11. So first tests are done and all seams to be working good.
    Here’s a link just to see what I’ve done so far.
    http://demo.themeskingdom.com/wds/submit/
    I’ll set form to send post as published although my plan is to set it draft and it needs to be approved by admin.
    This is form with fully customized google reCaptcha and it needs to have image in it png, jpg, jpeg, gif every other try should result some error.
    It’s not all done so it could have some minor bugs…
    Because of tight deadline I’ll send working code in a few days as soon as I clean it a bit so people can see it a bit better.

    Danko Dubajic

    1. Looks like I’ll have to wait until I’m home to look at the form. I’m stuck using IE7 at work, so I don’t think I’m seeing things as you designed them. But from what I can see, looks fantastic. Definitely appreciate you sharing the code when you have time!

        1. Yeah, IE7 is terrible. Unfortunately at my work I am stuck on Winows XP with IE7. I have no way to upgrade or use a different browser. It makes tinkering with my own website a treat. I’ll do some work in IE7, then go home and see what it really looks like!

  12. Hi nice article.

    I’m just wondering whether it is possible to use custom content type e.g. candidates lists where candidates will enter their personal details in form and it will create a custom content type post, i dont’ want to create conventioanl wordpress post , i rather create a separate custom content type candidates. candidates who love to apply for a job they will fill out the form and then a new post will be created under candidates list.

    what do you think ? is it possible? any article you wrote about this , let me know plz.

    1. Hi

      I sorted out nicely. I created custom content type candiates and user can enter their details into the form and after submission it creates a new post of candidates post type. Amazing. I also created thank you redirect page, works smoothly till now.

      Now I have an issue, how to validate the form ?

      currently I have 4 fields,

      post title (as it is being used as candidate name)
      email
      telephone and
      upload cv.

      i followed your code and used

      if ($_POST['title']!= ”) {
      $title = $_POST['title'];
      } else {
      echo ‘Please enter your name’;
      }
      so it validates when post title field is empty, but f created another two validation rules

      if ($_POST['cand_email']!= ”) {
      $cand_email = $_POST['cand_email'];
      } else {
      echo ‘Please enter your email’;
      }

      if ($_POST['cand_phone']!= ”) {
      $cand_phone = $_POST['cand_phone'];
      } else {
      echo ‘Please enter your Phone number’;
      }
      it sends an error after showing the message.
      it says header already sent out type message.

      let me know guys if you have similar issues.

      1. Hi Zakir. I didn’t use validation as mentioned in this post. I used some small java script. Will send some code tomorrow it won’t be hard to implement that in your code.

  13. <?php session_start();
    /*
    Template Name: FULL FORM TEST
    */
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" &#60;?php language_attributes(); ?>>
    <head profile="http://gmpg.org/xfn/11"><META CHARSET="UTF-8">

          
          <title>Some test</title>  

          <script src="<?php echo get_template_directory_uri()."/script/jquery/jquery-1.5.1.min.js";?>" type="text/javascript"></script>    
     
    <!--FRONT END POSTING  -->
    <?php
           
    if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_post") {
     
      // Do some minor form validation to make sure there is content
      if (isset ($_POST['site-title'])) {
        $sitename = $_POST['site-title'];
      } 
      
      if (isset ($_POST['site-link'])) {
        $siteurl = $_POST['site-link'];
      } 
      
      if (isset ($_POST['dev-name'])) {
        $devname = $_POST['dev-name'];
      } 
      
      if (isset ($_POST['dev-url'])) {
        $devurl = $_POST['dev-url'];
      } 
      
      if (isset ($_POST['dev-country'])) {
        $devcountry = $_POST['dev-country'];
      } 
      
      if (isset ($_POST['dev-twitter'])) {
        $devtwitter = $_POST['dev-twitter'];
      } 
     

      // ADD THE FORM INPUT TO $new_post ARRAY
      $new_post = array(
      'post_title'  =>  $sitename,
      'post_status'  =>  'publish',      // Choose: publish, preview, future, draft, etc.
      'post_type' =>  'post' //'post',page' or use a custom post type if you want to
      );

      //SAVE THE POST
      $pid = wp_insert_post($new_post);
      add_post_meta($pid, '01 Site URL', $siteurl, true);
      add_post_meta($pid, '02 Developer Name', $devname, true);
      add_post_meta($pid, '03 Developer URL', $devurl, true);
      add_post_meta($pid, '04 Developer Country', $devcountry, true);
      add_post_meta($pid, '05 Developer Twitter', $devtwitter, true);

      
      if ($_FILES) {
      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 THAT STARTED THE WHOLE FORM

    //POST THE POST YO
    do_action('wp_insert_post', 'wp_insert_post');

    ?>
    <!--FRONT END POSTING  -->

           
    <?php wp_head(); ?>
    </head>

    <body <?php $class='body'; body_class( $class ); ?>>

    <div class="front-end-holder">
        <div class="front-end-left">

        <form id="new_post" name="new_post" method="post" action="" class="front-end-form" enctype="multipart/form-data" onsubmit="return checkFormx(this)">

          <!-- images -->
          <fieldset name="site-image" class="site-image">
            <input type="file" name="image" class="file_input_hidden site-image file_upload" onchange="javascript: document.getElementById('fileName').value = this.value" />
          </fieldset>

          <!-- post name -->
          <fieldset name="developer-name" class="fieldset-first">
            <input type="text" id="dev-name" value="Developer Name" class="hideinput" tabindex="2" name="dev-name" />
          </fieldset>
          
          <fieldset name="developer-url" class="fieldset-first">
            <input type="text" id="dev-url" value="Developer URL" class="hideinput" tabindex="3" name="dev-url" />
          </fieldset>
          
          <fieldset name="deveoper-country" class="fieldset-last">
            <input type="text" id="dev-country" value="Country" class="hideinput" tabindex="4" name="dev-country" />
          </fieldset>
          
          <fieldset name="developer-twitter" class="fieldset-last">
            <input type="text" id="dev-twitter" value="Twitter Username" class="hideinput" tabindex="5" name="dev-twitter" />
          </fieldset>
        </div>
    <!--    left side-->
        <div class="front-end-right">
        
          <fieldset name="site-name">
             <input type="text" id="site-name" value="Site Name" class="hideinput" tabindex="6" name="site-title" />
          </fieldset>
          
          <fieldset name="site-url">
            <input type="text" id="site-url" value="Site URL" class="hideinput" tabindex="7" name="site-link" />
          </fieldset>
            
           <div class="clear-both"></div>
         </div>
    <!--right side form-->
    </div>
    </div>
    <div class="clear-both"></div
          
          <div id="error-message"></div>

          <fieldset class="submit">
            <input type="submit" value="Preview" class="frontsubmit" tabindex="40" id="submit" name="submit" />
          </fieldset>
        
          <input type="hidden" name="action" value="new_post" />
          <?php wp_nonce_field( 'new-post' ); ?>
          
        </form>
    <script type="text/javascript">

    function check_field(field,alerttxt,checktext){
      with (field)
      {
      var checkfalse = 0;
      if(field.value == ""){
        $('#error-message').empty().append(alerttxt);

      field.focus();checkfalse=1;}

      if(field.value==checktext)
      {  
        $('#error-message').empty().append(alerttxt);
        field.focus();checkfalse=1;
     
      }
       
      if(checkfalse==1){return false;}else{return true;}
     
      }
     
    }

    function checkFormx(thisform)

    {
      
    with (thisform)
    {
      var error = 0;    

      var siteurl = document.getElementById('site-url');
      if(check_field(siteurl,"Please insert your site URL","Site URL")==false){
       error = 1;
      } 
     var sitename = document.getElementById('site-name');
      if(check_field(sitename,"Please insert your site name","Site Name")==false){
       error = 1;
      } 
     var devtwitter = document.getElementById('dev-twitter');
      if(check_field(devtwitter,"Please insert your twitter username","Twitter Username")==false){
       error = 1;
      }
     var country = document.getElementById('dev-country');
      if(check_field(country,"Please insert your country","Country")==false){
       error = 1;
      }
     var devurl = document.getElementById('dev-url');
      if(check_field(devurl,"Please insert your URL","Developer URL")==false){
       error = 1;
      }
     var devname = document.getElementById('dev-name');
      if(check_field(devname,"Please insert your name","Developer Name")==false){
       error = 1;
      }

      if(error == 0){
        return true;
      }
      return false;
    }

    }

    </script>
        
        
        
        
        

        <script type="text/javascript">

    $(document).ready(function() {

    $('.front-end-holder .hideinput').addClass("idleField");
    $('.front-end-holder .hideinput').focus(function() {
    $(this).removeClass("idleField").addClass("focusField");
    if (this.value == this.defaultValue){
    this.value = '';
    }
    if(this.value != this.defaultValue){
    this.select();
    }
    });
    $('.front-end-holder .hideinput').blur(function() {
    $(this).removeClass("focusField").addClass("idleField");
    if ($.trim(this.value) == ''){
    this.value = (this.defaultValue ? this.defaultValue : '');
    }
    });

    });
    </script>
        
        
        
      </body>
    </html>

    * This source code was highlighted with Source Code Highlighter.

  14. I hope now that wp didn’t eat my code.
    This thing works as it is, just make .php file and add it to your wp root folder and make page with that template.
    Only thing it needs is jQuery so change path to your jquery.js.
    I used custom fields for post because I think it’s easier for admin to check post before approval. You can also add category, tags, etc just after inserting featured image, and above “} // END THE IF STATEMENT THAT STARTED THE WHOLE FORM”.
    Hope it helps you guys.

    1. Hi Danko,

      Cut and pasted your code above into a template. I cant seem to get it to work, the form displays okay but when i hit the display button I get the ‘The website cannot display the page’ error.

      Any ideas what I might be doing wrong, any feedback would be fantastic.

      Kane2010

  15. Hi all,
    Great tutorial, but I have been stumbling around with something and can’t get my head to it. I am using a plugin called wp-recipes which creates a custom post-type in the backend, with some custom labels to input data. This is all fine and I have set up the form on the page with no problems, the only thing that I for some reason don’t get done is saving those custom labels from the plugin. The title, tags and normal content saves no problem, but I just don’t get the custom labels to show up on the page when posting from the front end. All help is welcome!!

    1. Solved it by digging in the plugin and simply added the following lines to the code:

       $meta = $_POST['_my_meta']; 
       add_post_meta($pid, '_my_meta', $meta, true); 

      Thanks for the tutorial Voodoo!!

      1. I was tied up with school all weekend, but you got it all figured out! I was going to point you to another tutorial I had up here about working with meta data from the front end…. but you did exactly what the tutorial would have shown, good job!

  16. Is it fair to hope you will give us the chance to modify the post from the front end? Some clients should really be deprive from the excuse of modifying the post by login in the admin area at all.

    1. I would like to get that feature going…. but I don’t think I’ll have any time real soon. I’m super busy with school and work unfortunately. Have you tried the edit from front end plugin? I’m not sure if that only allows admins to edit, or what…. I haven’t tried it. My main problem is that I allow anyone to post, so how to control who can edit? Plus I use images on my form, and I haven’t been able to figure that part out, for previewing and editing. So yeah, basically it is my goal to get front end editing up here, just not sure when I’ll have time.

    2. This is a tricky thing actually.
      I haven’t tried much of that but there are some issues about that editing.
      What kind of editing client wants, picture upload, ….
      It’s fairly easy to create jQuery code that can change HTML inside tag, but if you want it to be serious editor you’ll have to enable shortcodes, picture upload with preview, etc, etc, and that’s really really hard.
      It’s something we just talked among us but no one actually started something more about that.
      I’m sure we’ll have to make something like that and as soon as we start it I’ll make some posts about it.
      Until then encourage your clients to learn WP admin :-D

      1. For now, I just tell people if they make a mistake that they need fixed, just make a new post. I check my site frequently. If I see a dup, I delete the first one. It’s not perfect, but it works fine. This works even better if the post submitted has to be moderated first.

    1. Yup, if you look through the comments here, it’s definitely something we’ve talked about. I would love to get edit capabilities going for sure. There are some issues to work through with regards to permissions, images, etc. If I can get some spare time away from work and school, I definitely plan to work on that, as I need that feature on one of my sites.

  17. I was thrilled when I saw that you had written a tutorial on this topic, Rev Voodoo. Your other tutorial on adding widgets to posts was so good.

    With a few tweaks and possibly one code correction, I got it to work and add images as attachments to posts. The possible code correction, by the way, was that the function was adding the attachment to $post_id where the wp_insert_post function was adding attachments to a variable named $pid.

    Once again, your generosity has gotten me over a hump. Thank you very much for sharing your WordPress schemes with us. :)

    1. Thanks, I’ll have to look in to that. The code I have up on here is a direct copy and paste from my form on my site, which is working great. But just because it’s working doesn’t mean I haven’t made some mistakes in the code!

  18. Very nice tutorial. I have been working on this functionality for a while, you gave me just the things I was missing. My question is: is there a way to edit/delete a post from the front end? Currently, I am using the front end code to allow users to manage their own coupons. I would like to allow them to edit/delete coupons that are in the list.

    1. If you look through the comments on this and related posts, we haven’t gotten there yet. It would definitely be a great feature. There are a few problems to work through. Editing basic posts wouldn’t be too hard, but if post meta and images are involved it gets harder… at least for me. Some folks have had success using jquery, and I hope to get to see some of that code, its not my strength.

      Another major problem is that, at least for me, I allow not signed in users to post through the form. I don’t see how to handle permissions with an edit/delete feature. If a not logged in user could edit or delete, then anyone could.

      I do want to figure this out soon, just been real busy lately. But I’ll take another look at it

  19. I agree that jquery will probably be the best way to handle this. I’m going to work and see what I can come up with. As for permissions to edit or post, this is how I am currently handling it:

    <?php
    // First check to see if this is the admin
     if (!current_user_can('update_core')) {
    	echo 'You are not authorized to use this feature';
    	}
    // I added a user capability so I check to see if the user has access
    elseif (!current_user_can('add_coupon')) {
    	echo 'You are not authorized to use this feature';
    	}
    // Put the form here
    else { }
    </php>
    
    1. A good way to do it for people who sign in. My form is used by people who never sign in for the most part, which presents the bulk of my issue! If you come up with a cool edit solution, I’d love to see it!

    2. Did you guy ever figure out how to edit and delete existing post from the front-end. Actually I am looking for a way to let a post author edit or delete his post from the front-end directly.
      Thanks for any guidance.
      What has been going on this section is one of the most important functionally of wordpress. If master, one could do everything with wordpress. This is the basis of all social networking, the ease for user to edit his posts. It will be nice to have a complete recapitulative of this. Preferably on a pfd.

      1. Man, I would love to get it going. I’ve only been frustrating myself! Thing is, I KNOW there has gotta be someone out there that could set this up in a day!

        My next goal, is to get the full editor involved. WP 3.3 is going to make that really easy to do. Once I get that going, it’s back to editor/delete. I think the delete thing will be simple, so long as your form requires the user to be signed in. The edit part still throws me. I think the basic info will be easy, probably meta won’t be hard too. Images have me a bit stumped…..

      2. I think this may work for deleting posts on the front end….

        <?php if (current_user_can('edit_post', $post->ID)) echo "<a href='" . wp_nonce_url("/wp-admin/post.php?action=delete&amp;post=$id", 'delete-post_' . $post->ID) . "'>Delete post</a>" ?>
        
  20. Cool! Just what I needed. I was using gravity forms for this, but it was limiting me. Just one thing, do you have any idea how to add a “create new category” in the form? This would be perfect for me!!

        1. I’ve never actually used it…. it just seems like it would work. If I get a chance, I’ll try to play around with it a bit….. I’m super tied up right now unfortunately.

  21. Hi guys,
    thank to this tutorial I started my project using front end posting. Later I created a user page that when one is logged in it shows a list of his listings and two buttons of edit and delete next to each listing. Both buttons are working in front end. User can delete his listings or edit them in front end same as creating a new one. if you’d lik to, I can do some posting later on when I will be home in my computer.

      1. i posted two codes below so you can take a look. first one if for “my-coupons.php” file and the other one is for “edit-coupons.php” file. however, i posted the “edit-coupon.php” code twice. the first one came out with an error so use the second post in the very bottom.
        i will probably make an entire post later try to simplify things. but for now you can look at the codes and make it work with your project.

  22. ok,
    so this is a template file called “my-coupons.php”. this is how i use it in my project but you will have to change few things to make it work with your site. the page should (it works for me) display the posts of a logged in user ( you can see at the top of the page there is a code checking if user is logged in or not) using a query posts of the current logged in user. so it will not display any other post beside those that belong to the logged in user. first to be displayed are the approved posts and below are the pending posts. the loop displays the title, the thumbnail, the content , the date the post was created and “edit” and “delete” buttons of each post. once you click on delete button the post should be deleted and when click on edit you will be directed to a “edit-coupon.php” file that i will post later. there you will be able to edit your post.
    in my site i create a button called ” My Coupons”. this button displays only when a user is logged in and when the user click on it he is being directed to the “my-coupons.php” file. that is how i created the button but of course you can do it however you want:

    .
    below is the entire code from my “my-coupons.php” file. i left it the way i use it. you will have to change in few places including the div ids and classes. i hope it will come out ok in this comment. i guess you can copy and paste in into a code editor to see it better.

    $current_user->ID,’post_status’ => ‘publish’ , ‘post_type’ => array( ‘coupons’ ) ) ); ?>

    <div id="post-” >

    <a href="”>post_title; ?>


    <input type="hidden" name="postid" value="” />


    <input type="hidden" name="postid" value="” />


    Pending Approval

    $current_user->ID,’post_status’ => ‘pending’ , ‘post_type’ => array( ‘coupons’ ) ) ); ?>

    <div id="post-” >

    <a href="”>post_title; ?>


    <input type="hidden" name="postid" value="” />


    <input type="hidden" name="postid" value="” />





  23. well, the code didn’t come out good.

    <?php if ( !is_user_logged_in()) {   					////////// check if user is logged in, if not direct him to login page or any other page
    	wp_redirect( 'www.site login page or home page' );
    	} else {
    ?>
    <?php
    /**
     *  template for displaying "My coupons" page.
     *  created by Eyal Fitoussi
     */
    if( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
    	 set_query_var( 'postid1', $_POST['postid'] );
    			
    	 wp_delete_post( get_query_var( 'postid1'), true ); ////////// delete choosen post
    	};
    	
    get_header(); ?>
    
        <div id="content" class="cf-bp-wrap" role="main">
                
            <h1 class="entry-title"><?php the_title(); ?></h1>   
    
            <?php query_posts( array( 'author' => $current_user->ID,'post_status' => 'publish' , 'post_type' => array( 'coupons' )  ) ); ?> <!-- create published posts query of the logged in user. change the post_type to your post type. -->
    
            <?php if ( !have_posts() ): ?>
                <br />
                <div class="info" id="message">
                    <p><?php _e( 'No coupons found.', 'coupons' ); ?></p>
                </div>
            <?php endif; ?>
                            
            <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <!-- display posts -->
    
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
                    <div class="entry-content">
    
                        <div class="my-coupon-ad">
    						<div id="coupon-info">
    							<div id="coupon-header">
    								<div id="coupon-title"><a href="<?php the_permalink(); ?>"><?php echo $post->post_title; ?></a></div>
    							</div> <!-- coupon header -->
    							<div id="info-holder">
    								<div class="coupon-image"><?php echo get_the_post_thumbnail( get_the_ID(), array( 200, 150 ) ); ?></div>
    								<div class="coupon-description"><?php the_content(); ?></div>		
    							</div><!-- infor holder -->
    							<div id="coupon-bottom">
    								<div id="creat-time">
    									<div><?php _e( 'Posted On - ', 'coupons' ); ?><?php the_date(); ?></div>
                                   	</div>	     
                                </div> <!-- coupon bottom -->
    						    <div id="coupon-buts">
    						        <form id="edit-coupon" action="http:// Url to the file you create for editing post" method="post">  <!-- button to edit post -->
    									<input type="hidden" name="postid" value="<?php the_ID(); ?>" />
                						<input type="submit"  value="Edit" />
           						 	</form>
           						 	<form id="delete-coupon" action="" method="post"> <!-- button to delete post -->
    									<input type="hidden" name="postid" value="<?php the_ID(); ?>" />
                						<input type="submit"  value="Delete" />
           						 	</form>
           						 </div> <!-- coupon-buts -->
    						</div><!-- coupon info-->
    								
                        </div> <!-- my-coupon-ad -->
    
                    </div><!-- .entry-content -->
    						
                </div><!-- #post-## -->
    
            <?php endwhile; ?>
            <?php wp_reset_query(); ?>
            <div class="clear"></div>
                    
            <h3>Pending Approval</h3>
                    
            <?php query_posts( array( 'author' => $current_user->ID,'post_status' => 'pending' , 'post_type' => array( 'coupons' )  ) ); ?> <!-- create pending posts query of the logged in user. change the post_type to your post type. -->
    
            <?php if ( !have_posts() ): ?> <!-- if no pending post found write a message -->
            <br />
            <div class="info" id="message">
    			<p><?php _e( 'No coupons found.', 'coupons' ); ?></p>
            </div>
            <?php endif; ?>
                            
            <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?> <!-- display pending posts -->
    		
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <div class="entry-content">
                        <div class="my-coupon-ad">
    						<div id="coupon-info">
    							<div id="coupon-header">
    								<div id="coupon-title"><a href="<?php the_permalink(); ?>"><?php echo $post->post_title; ?></a></div>
    							</div> <!-- coupon header -->
    							<div id="info-holder">
    								<div class="coupon-image"><?php echo get_the_post_thumbnail( get_the_ID(), array( 200, 150 ) ); ?></div>
    								<div class="coupon-description"><?php the_content(); ?></div>		
    							</div><!-- info-holder -->
    							<div id="coupon-bottom">
    								<div id="create-time">
    									<div><?php _e( 'Posted On - ', 'coupons' ); ?><?php the_date(); ?></div>
                                   	</div>	       
                                </div> <!-- coupon bottom -->
    						    <div id="coupon-buts">
    								<form id="edit-coupon" action="http:// Url to the file you create for editing post" method="post">  <!-- button to edit post -->
    									<input type="hidden" name="postid" value="<?php the_ID(); ?>" />
    									<input type="submit"  value="Edit" />
    								</form>
    								<form id="delete-coupon" action="" method="post"> <!-- button to delete post -->
    									<input type="hidden" name="postid" value="<?php the_ID(); ?>" />
    									<input type="submit"  value="Delete" />
    								</form>
           						 </div> <!-- coupon buts -->
    						</div><!-- coupon info-->
                        </div> <!-- my-coupon-ad -->
    				</div><!-- .entry-content -->		
    			</div><!-- #post-## -->
    
            <?php endwhile; ?>
            <?php wp_reset_query(); ?>
                    
    	</div><!-- #content -->
    			<?php locate_template( array( 'left-sidebar.php' ), true ); ?>
                
    <?php get_footer(); ?>
    <?php } ?> <!-- user is logged in -->
    

    this is the “my-coupons.php” file

  24. in the code above you need to change the “post_type” in the query_posts to your post type.

    <?php query_posts( array( 'author' => $current_user->ID,'post_status' => 'publish' , 'post_type' => array( 'coupons' )  ) ); ?>
    

    you also need to add the url of the “edit-post.php” file that you will create later to the form.

    <form id="edit-coupon" action="http:// Url to the file you create for editing post" method="post">
    

    and in the very top you add the url where you wont the user to be redirect if he is not logged in:

    wp_redirect( 'www.site login page or home page' );
    
  25. the code below is the file “edit-coupon.php”. this is how i use it and it works perfect. it is very similar to the “front end post form” from the original tutorial by voodoo. you will have to change things around to make it work with your site. i put comments next to some of the places that need to be changed. also look at the fieldsets of the form and change them to your fieldsets .
    when you edit a post all the fields of the form should be field with the current information of the post. categories should displayed by dropdown menu when the current category is selected.
    there is a small javascript that check if the image need to be change or not. that is how i use it , if you find a better way please let me know.
    it will look pretty messy at first but if you open it in a code editor ( i like notepad++) it will be easier to look around. probably will not work at first shot but you you guys have any questions you are more then welcome to ask me.

    <?php if ( !is_user_logged_in()) { 
    	wp_redirect( 'http://url to login page' ); // url to redirect user if he is not logged in
    	} 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']); // get the post id that we are editing. do not change it !!
    	
    	// code below is to save the information that we entered in the form
    	// edit the names to your fields names, add or remove. 
    	// need to match the names from your "new post" form
    	
    	$title = $_POST['title'];
    	$description = $_POST['description'];
    	$street = $_POST['street'];
    	$apt = $_POST['apt'];
    	$city = $_POST['city'];
    	$state = $_POST['state'];
    	$zipcode = $_POST['zipcode'];
    	$phone = $_POST['phone'];
    	$tags = $_POST['post_tags'];
    	$image = $_POST['image'];
    	
    	$post_to_edit->post_title = $title;
    	$post_to_edit->post_content = $description;
    	
    	
    	$pid = wp_update_post($post_to_edit); 
    	
    	// save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false)
    	wp_set_post_terms($pid, array($_POST['cat']),'coupons_categories',false); // change 'coupons_categories' to the name of your category taxonomy 
    	wp_set_post_terms($pid, array($_POST['post_tags']),'coupons_tags',false); // change 'coupons_tags' to the name of your tags taxonomy 
    		
    
    	//UPDATE CUSTOM FIELDS change the custom fields names , street, apt ,city..... to your custom fileds name. you can add remove them.
    	update_post_meta($pid, 'street', $street);
    	update_post_meta($pid, 'apt', $apt);
    	update_post_meta($pid, 'city', $city);
    	update_post_meta($pid, 'state', $state);
    	update_post_meta($pid, 'zipcode', $zipcode);
    	update_post_meta($pid, 'phone', $phone);
    	
    
    	//REDIRECT 
    	wp_redirect( 'www.url to "my-coupons.php" page' ); // will go to this page when doen editing
    
    	//INSERT OUR MEDIA ATTACHMENTS
    	if ( $_POST['change_image'] == 1) {  			//this will check if need to change the image or not. dont change it!!
    		if ($_FILES) {
    			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> 			// this script check if user want to change the image or not. do not change nothing in here.
    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'); ?> <!-- change 'coupons_categories' to the name of your taxonomy -->
    <?php $coupons_tags = strip_tags( get_the_term_list( $post_to_edit->ID, 'coupons_tags', '', ', ', '' ) ); ?> <!-- change 'coupons_tags' to the name of your taxonomy -->
    
    	<!-- the code below is to pull the current category of the post -->
    <?php $term_name = strip_tags( get_the_term_list( $post_to_edit->ID, 'coupons_categories', '', ', ', '' ) ); ?> <!-- change 'coupons_categories' to the name of your taxonomy -->
    <?php $term_obj = get_term_by('name', $term_name, 'coupons_categories'); ?> <!-- change 'coupons_categories' to the name of your taxonomy -->
    <?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', // change 'coupons_categories' to the name of your taxonomy 
        '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" />
    			</fieldset>
    
    			<!-- post Category -->
    			<fieldset id="category">
    				<label for="cat" ><?php wp_dropdown_categories( $args ); ?></label> <!-- dropdown categories to choose from when the current category is selected -->
    			</fieldset>
    			
    			<!-- post Content -->
    			<fieldset class="content">
    				<label for="description">Description:</label><br />
    				<textarea id="description"  tabindex="15" name="description" ><?php echo $post_to_edit->post_content; ?></textarea>
    			</fieldset>
    			
    			<!-- images - will display a check box for the user to choose if to change the image or not -->
    			<?php echo get_the_post_thumbnail( $post_to_edit->ID, array( 200, 150 ) ); ?><br />
    			<input type="checkbox" name="c1" onclick="showMe('image', this)" >Change Image
    			<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>
    			
    			<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" />
    			</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" />
    			</fieldset>
    			
    			<fieldset class="city">
    				<label for="city">City:</label><br />
    				<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'city', true); ?>" id="city" tabindex="20" name="city" />
    			</fieldset>
    			
    			<fieldset class="state">
    				<label for="winerating">State:</label><br />
    				<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'state', true); ?>" id="state" tabindex="20" name="state" />
    			</fieldset>
    			
    			<fieldset class="zipcode">
    				<label for="zipcode">Zip Code:</label><br />
    				<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'zipcode', true); ?>" id="zipdode" tabindex="20" name="zipcode" onKeyPress="return checkIt(event)" />
    			</fieldset>
    			
    			<fieldset class="phone">
    				<label for="phone">Phone Number:</label><br />
    				<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'phone', true); ?>" id="phone" tabindex="20" name="phone" onKeyPress="return checkIt(event)"/>
    			</fieldset>
    			
    			<!-- post tags - will display the current post tags and user can add or remove them -->
    			<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" />
    			</fieldset>
    									
    			<fieldset class="submit">
    				<input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" />
    				
    			</fieldset>
    			<input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" />
    			<input type="hidden" name="action" value="edit_post" />
    			<input type="hidden" name="change_cat" value="" />
    			<input type="hidden" name="change_image" value="" />
    		</form>
    		
    
    		<!-- END OF FORM -->
    			
    					</div><!-- .entry-content -->
    				</div><!-- #post-## -->
    
    				
    			</div><!-- #content -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    <?php } ?> <!-- user is logged in -->
    
      1. i thought that you might want to do it. i would have done it a little more organize but it is a little hard when i do it as a comment.

        1. I would love to make this out as a full post. But I’m not going to be able to play with the code for a while. School and work are killing me! You are welcome to make a guest post if you’re ever in the mood!

          1. that is a good idea. i think i will do it. for now i found that there is a small error in the edit-coupon.php so ill post it below again.

  26. there was a small error in the first post of the edit-coupon.php. this is the fixed code (i hope it will come out with no errors this time).

    
    <?php if ( !is_user_logged_in()) { 
    	wp_redirect( 'http:// login page or any other page' ); // this will redirect user if not logged in. 
    	} else {
    ?>
    <?php
    /*
    Template Name: new coupon form
    */
    ?>
    <?php
    
     if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "edit_post" && isset($_POST['postid'])) { // 'postid' is the ID of the post that we are editing. postid created in the my-coupons.php page when clicked on "Edit" button of a post.
    
    	$post_to_edit = array();
    	$post_to_edit = get_post($_POST['postid']); // get the post id that we are editing. do not change it !!
    
    	// code below is to save the information that we entered in the form
    	// edit the names to your fields names, add or remove.
    	// should match the names from your "new post" form
    
    	$title = $_POST['title'];
    	$description = $_POST['description'];
    	$street = $_POST['street'];
    	$apt = $_POST['apt'];
    	$city = $_POST['city'];
    	$state = $_POST['state'];
    	$zipcode = $_POST['zipcode'];
    	$phone = $_POST['phone'];
    	$tags = $_POST['post_tags'];
    	$image = $_POST['image'];
    
    	$post_to_edit->post_title = $title;
    	$post_to_edit->post_content = $description;
    
    	$pid = wp_update_post($post_to_edit); 
    
    	// save taxonomies: post ID, form name, taxonomy name, if it appends(true) or rewrite(false)
    	wp_set_post_terms($pid, array($_POST['cat']),'coupons_categories',false); // change 'coupons_categories' to the name of your category taxonomy
    	wp_set_post_terms($pid, array($_POST['post_tags']),'coupons_tags',false); // change 'coupons_tags' to the name of your tags taxonomy 
    
    	//UPDATE CUSTOM FIELDS change the custom fields names , street, apt ,city..... to your custom fileds name. you can add or remove them.
    	update_post_meta($pid, 'street', $street);
    	update_post_meta($pid, 'apt', $apt);
    	update_post_meta($pid, 'city', $city);
    	update_post_meta($pid, 'state', $state);
    	update_post_meta($pid, 'zipcode', $zipcode);
    	update_post_meta($pid, 'phone', $phone);
    
    	//REDIRECT
    	wp_redirect( 'www.url to "my-coupons.php" page' ); // will go to this page when doen editing
    
    	//INSERT OUR MEDIA ATTACHMENTS
    	if ( $_POST['change_image'] == 1) {  			//this will check if need to upload new image or not. dont change it!!
    		if ($_FILES) {
    			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(); ?>
    <?php /* this script check if user want to change the image or not. do not change nothing in here. */ ?>
    <script> 			
    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 /* change 'coupons_categories' to the name of your taxonomy */ ?>
    <?php $coupons_tags = strip_tags( get_the_term_list( $post_to_edit->ID, 'coupons_tags', '', ', ', '' ) ); ?> <?php /* change 'coupons_tags' to the name of your taxonomy */ ?>
    
    	<!-- the code below is to pull the current category of the post -->
    <?php $term_name = strip_tags( get_the_term_list( $post_to_edit->ID, 'coupons_categories', '', ', ', '' ) ); ?> <?php /* change 'coupons_categories' to the name of your taxonomy */ ?>
    <?php $term_obj = get_term_by('name', $term_name, 'coupons_categories'); ?> <?php /* change 'coupons_categories' to the name of your taxonomy */ ?>
    <?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', // change 'coupons_categories' to the name of your taxonomy
        '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" />
    			</fieldset>
    
    			<!-- post Category -->
    			<fieldset id="category">
    				<label for="cat" ><?php wp_dropdown_categories( $args ); ?></label> <!-- dropdown categories to choose from when the current category is selected -->
    			</fieldset>
    
    			<!-- post Content -->
    			<fieldset class="content">
    				<label for="description">Description:</label><br />
    				<textarea id="description"  tabindex="15" name="description" ><?php echo $post_to_edit->post_content; ?></textarea>
    			</fieldset>
    
    			<!-- images - will display a check box for the user to choose if to change the image or not -->
    			<?php echo get_the_post_thumbnail( $post_to_edit->ID, array( 200, 150 ) ); ?><br />
    			<input type="checkbox" name="c1" onclick="showMe('image', this)" >Change Image
    			<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>
    
    			<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" />
    			</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" />
    			</fieldset>
    
    			<fieldset class="city">
    				<label for="city">City:</label><br />
    				<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'city', true); ?>" id="city" tabindex="20" name="city" />
    			</fieldset>
    
    			<fieldset class="state">
    				<label for="winerating">State:</label><br />
    				<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'state', true); ?>" id="state" tabindex="20" name="state" />
    			</fieldset>
    
    			<fieldset class="zipcode">
    				<label for="zipcode">Zip Code:</label><br />
    				<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'zipcode', true); ?>" id="zipdode" tabindex="20" name="zipcode" onKeyPress="return checkIt(event)" />
    			</fieldset>
    
    			<fieldset class="phone">
    				<label for="phone">Phone Number:</label><br />
    				<input type="text" value="<?php echo get_post_meta($post_to_edit->ID,'phone', true); ?>" id="phone" tabindex="20" name="phone" onKeyPress="return checkIt(event)"/>
    			</fieldset>
    
    			<!-- post tags - will display the current post tags and user can add or remove them -->
    			<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" />
    			</fieldset>
    
    			<fieldset class="submit">
    				<input type="submit" value="Post Review" tabindex="40" id="submit" name="submit" />
    
    			</fieldset>
    			<input type="hidden" name="postid" value="<?php echo $post_to_edit->ID; ?>" />
    			<input type="hidden" name="action" value="edit_post" />
    			<input type="hidden" name="change_cat" value="" />
    			<input type="hidden" name="change_image" value="" />
    		</form>
    
    		<!-- END OF FORM -->
    
    					</div><!-- .entry-content -->
    				</div><!-- #post-## -->
    
    			</div><!-- #content -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    <?php } ?> <!-- user is logged in -->
     

    also look at every fieldset. in the value of the textarea or the input filed there is a code that echo the current value of the post (custom field or text area) to the fields before the user edit them. make sure you change the fields name to your name.
    look at the value of the input field for example:

    <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" />
    </fieldset>
    
    1. Alright, I made you a contributer…. o I would guess that means you can post now? :) I’ve honestly never done that before…. so have fun! Any questions, shoot em my way rvoodoo (at) voodoopress (dot) com. Appreciate you trying to help all the folks out. Lots of people are interested in what you’ve got going here!

        1. Your comment broke the 100 comment mark. That’s a VoodooPress first on a post! Cool. I’m just super happy a reader has offered a solution to a problem so many people have been looking for help with. I personally wasn’t going to have time to ecen think about any coding for at least a month.

    1. this is a great plugin. actually i was using this plugin before i created the front end edit form. However, some things with the plugin didn’t go well with my project and that is when i removed it.

      1. Which plugin? The article I linked there is referring to the upcoming WP 3.3, which will simply allow us to use the backend WP editor on the frontend. Simple code, no plugins required. I really want to play some more. It might make image uploads and everything so much easier! That would be cool! :)

          1. If you would, yes please! WP 3.3 may not be out for a month or more. Also, what we have put together works now, for sure. I haven’t even begun to mess with the 3.3 code yet, and it may not be as easy to use as it implies. Or be as flexible. I think between my posts, and what you have, we have a functional and comprehensive solution that folks can use today.

  27. If you check out the plugin ‘WP User Frontend’ [http://wordpress.org/extend/plugins/wp-user-frontend/], you’ll see that most of the editing is completed. I used this with a combo of Profile Builder and it’s working flawlessly. I’ve completely eliminated the need to see anything about WordPress on [http://www.libertyguide.com].

    For the editing, I hacked a form together for both jobs and opportunities, so the editing could be written a little better.

    1. Oh there are several plugins that accomplish a variety of front end tasks. Personally, I am looking to accomplish the task without relying on a plugin, as this is a core feature of a site, and I don’t want to rely on a plugin that may break on an update or no longer be supported. Plus, it’s plain fun to figure this stuff out! But thanks for the link, some readers may find that quite useful.

    1. You could register a default user, and pass the ID of that user to post_author I would think. Maybe conditionalize that on is_user_logged in, so if they are logged in, we don’t assign a post_author, as it gets credited to them automagically, if not logged in assign post_author to your default.

        1. Hi all,

          i have tried submit post by not registered user but without success. I used this:
          ‘post_author’ => $authorID,
          This author is only for not registered user, but when i want to send post i always get
          “Page not exist and post is not saved”. Do you have some idea?

          Thanks a lot. Jan

  28. I have this working pretty well… Only question I have is..
    I want each “poster” to be able to add their name (author) to the post they submit.
    Adding ‘post_author’ into the new_post array doesn’t seem to work.

    I don’t want them to have to create an account. I just want it so they can add their name into the submitted post and have it displayed somewhere on the post :)

    Is there a way to get that working?

    1. I would probably just use a custom field for this. I don’t think we can use post_author, as that is expecting an ID of a registered user. Since they aren’t registered, they wouldn’t have an ID. Maybe conditionalize that field to only show up for people who aren’t logged in.

  29. Again, great work. Is there any way to add a default image to this? I’ve edited the ” if ( has_post_thumbnail() ) {…” function for my theme, and it works perfectly if I create a post through the regular WordPress admin area and leave out the featured image. However, when I leave the image area of this form blank, no default image displays. Any ideas? Thanks.

      1. Thanks for the reply. I ended up just putting an “if ($_POST['ad_image'] != “”)” statement around the upload code. If there’s something in the file upload field, run it. Else, skip it entirely. That way the “if ( has_post_thumbnail() ) ” function in function.php works as intended. Cheating I suppose, but thems the skills I have. Thanks again for your help.

  30. Great post… I have added this to a project and love that it easily adds the post. I would like the ability to add images… any thoughts? Would actually prefer a simple upload as I do not want the user to actually use the WP media uploader. The user will be a logged in Author, and will have the capability to upload media. But I would rather keep the image uploads as simple as adding a few fields (specific number of images).

    Any ideas would be great and definitely appreciated.
    Ed

  31. I seem to be having problems with this.
    When I try to select a category it will forward to a search page with the category I selected.
    Any ideas?
    Thanks In advanced
    James

      1. hey,
        Once I select a category from the drop down menu (without clicking submit) it redirects to a list of posts from that category.
        I believe I have 2 search plugins installed.
        Thanks :)

        1. Oops. My last comment got lost. (I just transferred hosts). Anyway, deactivate the plugins and test. They must be hijacking the category code. Absolutely nothing is this code would cause any actions to occur on cat selection.

      1. What I would love, is for someone to finish this whole project off! Here’s the gig, I figured this out for a specific need. There was almost nothing around the web for this project at the time. Several things are missing… we don’t have functioning validation, we don’t run any sort of checks, and on the media upload portion, we don’t check what’s being uploaded (the upload is a different portion).

        I’m tied up like crazy with work and school, neither of which have anything to do with WordPress. So I get precious little time to do the fun stuff. I’d love to teach myself some more… but I teach myself things that I need to learn for my sites. I’ve moved on to using Gravity Forms for my front end posting. So this isn’t something I can afford to dive into rigt now.

        We’ve got a great start here, we’ve recently had guest posts showing us how to delete and edit these posts from the front end. What would be awesome is for someone to grab this, clean it up a little, get what’s missing in place, and have an awesome and useful tutorial that a tonne of people are looking for.

        If anyone gets around to putting it all together, it would be very helpful to the community I’m sure! Hell, I’d probably throw in a VoodooPress hoodie or something for it! (I’m paying for school, so I’m broke! But I can do a little something right?)

  32. Hello,
    Grate tutorial,

    So i have some problems. First i tried to write my own code from the tutorial but that didn’t work out so what i did was just simply to copy al of the code and from there tried to get it to work but i get the same error message: ” Error: Form elements must not have name or id of “submit”. ”

    Hoped that some one where able to help me here.

    Best.

    1. Yup, should be a simple fix. I assume you are using Contact Form 7 on your site? It conflicts with this code. The simple way to fix that is to only allow CF7 to load on pages where you actually need it (ie. where you have a form displayed).
      http://vudu.me/4o
      Toward the bottom of that page you can see an example code for blocking CF7 when it isn’t needed.

      1. Hello, and thank you for answer.
        Got it sorted quiet well.

        So I have a fallow up question on this….

        So now i need two fields in my wp_post table to post FB access_token and user_id. I simply went in to the DB and created two varchar(255) fields, and added changed the post code to:

        $new_post = array(
        	'post_title'	=>	$title,
        	'post_content'	=>	$description,
        	'post_category'	=>	array($_POST['cat']),  // Usable for custom taxonomies too
        	'tags_input'	=>	array($tags),
        	'post_status'	=>	'draft',           // Choose: publish, preview, future, draft, etc.
        	'post_type'	=>	'post',  //'post',page' or use a custom post type if you want to
        	'user_id' => $user,
        	'access_token' => $access_token,
        	);
        

        Though it seams like it doesn’t post it to the DB. Do you maybe know why ?

        Anything you can help me with ?

        1. Well, it’s a bit hard for me to fully qualify an answer without knowing what yer doing, where the data comes from, what it’s used for, etc. But in general, custom fields are super simple to use.

          http://vudu.me/69 is my article about using them with this front end post method

          1. Well to explain what I’m doing I’m building a facebook app which will post a text to our blog and we will translate it and send back a link to our blog with the text.

            so what have to do is store your facebook ID and your access_token (your allowance for us to post something on your wall) this information is not to be seen by the viewer i just need to get it in to the database so i can fetch it for posting on your FB wall.

            I assume that i have to have to store it together with the post since I’m sending back the url to that exact post to the Facebook wall.

            But you think the meta box is the way to go ?

  33. Hello. Thank you for this awsome tutorial. I have one question maybe you can help me.

    After I hit post button everything works well except if I hit refresh on the page the form sends me the post again. If i refresh the page 10 times after posting I will have 10 posts. Any ideas on how to fix that? Thanks

    1. When you submit the post, you have it set up to stay on the same page? In my code above, I use a wp_redirect to go to the new post. Redirecting there, or to a thank you page, or some other landing page would keep that from happening I would think. Or does your redirect just not work?

  34. Hi Rev. Voodoo, thanks for this great tutorial! You make me really fast and easy adding this function to my site. I have just a question: I need to edit the date of the post by the form, how can I do?

    1. If you are comfortable with code it is probably easier. I actually switched over to using a plugin for doing this all… it was easier to maintain to me. I use Gravity Forms, which I’ll admint is a bit expensive. There is another new plugin out for people to check out…. Ninja Forms I believe it’s called. I just saw a write-up about it the other day. It’s a lot cheaper… like $30 I think. It also allows for front end posting. I haven’t tried it, but figured I’d post that here for people looking for a plugin option!

  35. (This is a little off topic, but I figured some VoodooPress insight might guide my way).

    Is it possible to have a comment form (displayed on a generic page) that allows the user to comment on ANY post?

    The user would have to select which post to comment on (from a dropdown or checkbox or otherwise) and then that post ID is passed on Submit (ensuring the comment relates to the selected post)? I’ve done much Googling with no success. Hope someone can help.

    1. Yeah, it would be possible for sure… I’m not sure it’s something I can come up with… I’m certain it would require some sort of jQuery magic, to be able to list all the posts, and then feed the selected post ID in with the comment. jQuery isn’t my strength… yet…

  36. How am I able to display subcategories in a dropdown list that users can select? For example, say I have category Dog with Big and Small as subcategories and a category Type with Fur and Hair as subcategories, how can I allow users to click the dropdown list Dog and have that display Big and Small as choices and when one is selected that gets posted as the selected sub category, then also click the dropdown list Type and choose from Fur or Hair? So say you selected Big and Hair in those two dropdown lists, that post should then be listed under Big and Hair subcategories.

    Im noticing this line:

    but my problem is I dont know how to edit that to display a dropdown of a certain category

    Code would be much appreciated :) I thank you all in advance for this lovely post and especially for a response to this question

  37. Wow dude thanks, thats a pretty lengthy tutorial and exactly what i’m looking for. Can I ask how you manage to create such great content, reply to all the comments and have a job? You must work like the Flash mate :)

  38. hey man! Great tutorial. I am a bit of a newbie to this. I have a nonprofit dedicated to the nearly 10,000 animal euthanized every day. What I want is for a user (whos is not logged in or registerd) to be able to write their own post for an animals. Please check out my website. http://www.alovinggoodbye.org and the page I am trying to create -> http://alovinggoodbye.org/?page_id=480

    If you could lead me in the right direction I would really really appreciate any assistance. I have spent the entire weekend trying to get this to work with no luck. Thank you !

    David Hendrickson

    1. What problems are you running into with the code? It’s just not working? Any particular errors or anything? I’m personally not really able to support anything right now – I’m working far more than full time, and attending school full time. It’s impossible for me to do just about anything right now. While I love this code that I pieced together, I just haven’t been able to work on it any more… I personally use gravity forms to handle my posting from front end functions on my other sites. If I get some spare time between classes anytime soon, I’d love to be able to run through this code and clean it up, add some functionality, etc…. but I can’t really do any of that right now.

  39. I have two questions:

    1. The form is working properly, including the custom fields, but when the post is created it says “No Categories.” I am selecting the categories, but they are not being added to the post when it is created. I am using a custom taxonomy, but I think I have made the necessary changes. What am I doing wrong?

    2. Is there a way to use the rich text editor instead of textarea?

    Help would be appreciated!

    1. Nevermind. I figured it out. Here is the code you need to be able to make the category and tags work for a custom taxonomy:

       
                   //SET OUR TAGS AND CATEGORIES UP PROPERLY
      	wp_set_post_terms( $pid, $_POST['post_tags'], 'listing_tag', false );
      	wp_set_post_terms( $pid, $_POST['cat'], 'listing_category', false );
      
        1. It absolutely would! This series of posts has grown kind of convuluted. In a couple of the posts (or in the comments) I had mentioned that! I was hoping to move further on this project, and just pretty much haven’t had time since I got started. It’s rough around the edges, and needs finishing up!

    2. There is, theoretically, a way to add in the normal editor. You might want to do a bit of research on using wp_editor. They opened it to be used in core, I just haven’t had a chance to get to using it yet. I do hope to get to playing with that soon, I’d like to figure out using it!

  40. Hi Rev,
    Found your site very informative, but i am looking for a php script which i can upload on my server and allow outsourced bloggers to submit their work direct and get it posted(draft) to other self hosted wp blog without sending them to it. Any help would be highly appreciate.
    Thanks
    Deep

  41. Hi Rev. Voodoo,

    I’ve recently been working on some code based on this tutorial, but for some reason when I submit the form I have created (using the same principles as your form), it just resets the form and nothing is entered into $_POST, so if statement is completely bypassed.

  42. I have two small question. Can this method be used in combination with the Advanced Custom Fields plugin?
    I know acf has its own method to create forms, at the moment I have a page that’s broken and I want to go back to the regular functions of WordPress. The other question is, is it also possible to update a post that already exists? I think it is possible, but do you also have a tutorial that describes that?

  43. i have little question, how user to post through this method when their post have image, i mean the user need upload the image. can you explaine to me how to doing thats

  44. If there’s an error on images upload, form is cleaned up. It’s possible keep text inserted by user (if an user write a long post and do a mistake with upload, he will rewrite all again :( ) and ask him to correct only the problem?

  45. A good way to do it for people who sign in. My form is used by people who never sign in for the most part, which presents the bulk of my issue! If you come up with a cool edit solution, I’d love to see it!

  46. A little question: if an user miss a field and submit, the page shows an error and cleans all the form. Is it possible keep text written and allow user to complete only the empty field?
    tnx

  47. Hi,
    First of all thanx for great post. I am using this and it’s works fine but when i upload other extension’s file like .doc,.html it dosen’t give any error. how can i show error when user upload other extension’s file. i want to upload only jpeg/jpg/png images.

  48. Pingback: Anonymous
  49. You have created an awesome tutorial on front-end content management for WordPress. I had been searching around Google, bumping into plugins, until I discovered your articles, which have saved my life. Great job and keep it up, please, for the good of humanity!

    If I may ask, can we replicate the backend content form into the frontend? With complete functionality? With all the text editing functions, uploading media etc, center text, bold it and everything. Because just an input box has no use in it for the enormous library I am preparing for my university.

    I will keep looking of course, in case I missed it (there has to be something somewhere) – but I am really looking forward to your reply!

  50. Has anyone got the ‘Multiple Category Select” to work, I can’t seem to make it work? I’ve created parent categories and the call the children to create the separate groups.
    wp_dropdown_categories( ‘tab_index=10&taxonomy=category&depth=2&child_of=62&hide_empty=0&hierarchical=1′ ); wp_dropdown_categories(‘tab_index=10&taxonomy=category&depth=2&child_of=14&orderby=name&hide_empty=0′);
    wp_dropdown_categories(‘tab_index=10&taxonomy=category&depth=0&child_of=32&orderby=name&hide_empty=0&hierarchical=0′);
    Anyone had success with this?

  51. Just got the multiple selection working by using $select_cats1 and Select_cats2 etc in different fieldsets. The problem I have now is I can’t see the dropdowns properly, just a one line window with dropdown behind it.. This maybe in my CCS but I’m not applying anything directly and there are no height restrictions in my input CSS styles?

  52. OK category-template.php applies a ‘postform’ class to the dropdown which means I can open the window up to see the scroll down, but it is actually a scroll down and doesn’t answer why the usual dropdown is not appearing in the wp_dropdown usual style?

Leave a Reply