Guest User

update tags on frontend

a guest
Dec 5th, 2011
322
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //on the fronted, displaying to user, above post, maybe in single.php
  2.  
  3. <form id="cadastro" name="cadastro" method="post" action="" enctype="multipart/form-data">
  4. <label for="ca_tags">Tags:</label>
  5. <input type="text" id="ca_tags" name="ca_tags" maxlength="254" />
  6.  
  7. <small>(comma separated)</small>   
  8.  
  9. <input type="hidden" name="page" id="page" value="<?php echo $post->ID; ?>"/>
  10. <?php wp_nonce_field('new-tag','tag-nonce'); ?>  
  11. <input type="submit" value="Enviar anúncio para aprovação" />
  12. </form>
  13.  
  14. //on top of file, the same single.php
  15.  
  16. if(!empty($_POST) && wp_verify_nonce($_POST['tag-nonce'],'new-tag')) {
  17.  
  18. if($_POST['ca_tags']){$tags = array('tags' => $_POST['ca_tags']);}
  19.     else{$tags = array('tags' => '');}
  20.  
  21. wp_set_post_terms($post->ID, $tags, 'tags' );
  22. }
  23.  
RAW Paste Data