Wordpress - Delete all tags by Post ID
صفحه اصلي

Wordpress - Delete all tags by Post ID

I've got a function to add a tag by post ID, but now I would like to delete all the current tags for that ID before adding my new tags?

Does anyone know a built in function or wordpress query to do this?


Why should define('RELOCATE',true) be removed from wordpress config?


Posts in Custom postype not visible on frontpage wordpress
If you must access the database directly (PhpMyAdmin), the quickest way is a SQL request. Giving different Post page for same type based on category or Custom Taxonomy. Wordpress Permalink hide directory name Look at the database schema in the codex :. drag and drop the widgets
DELETE FROM wp_term_relationships WHERE wp_term_relationships.object_id = 'yourPostId' AND wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id AND wp_term_taxonomy.taxonomy = 'post_tag'; 
WARNING : obviously, modifying directly the database is dangerous. WP ecommerce – Flow Player not working on product pagesBe careful doing that.. WordPress 3 multisite - Grabbing another blogs menu
importing jquery into wordpress


Should guidance you receive there:. Wordpress API: Add / Remove Tags on Posts. I found this function: wp_delete_term See if it helps you....


I pieced this toreceive her. Its pure database work, for the reason this I believe there is no quick function to delete a tag via ID, (although I am still not 100% certain)..
//define array of tags $tags = array("new tag","new tag 2");      //define post ID $val = 254;   //delete tags associated to post id $query = "SELECT * FROM ".$table_prefix."term_relationships tr JOIN ".$table_prefix."term_taxonomy tt ON tr.term_taxonomy_id=tt.term_taxonomy_id WHERE tr.object_id='$val' AND tt.taxonomy='post_tag'"; $result = mysql_query($query); if (!$result){echo $query; echo mysql_error();}  while ($arr = mysql_fetch_array($result)) {         $tid = $arr['term_taxonomy_id'];         $query2 = "DELETE FROM ".$table_prefix."term_relationships WHERE term_taxonomy_id='$tid'";         $result2 = mysql_query($query2);         if (!$result2){echo $query2; echo mysql_error();} }   //add tags to post id            wp_add_post_tags($val,$tags); 

60 out of 100 based on 55 user ratings 170 reviews