So if you’re sure you want to delete the actual term as well as the relationship that assigns the term to the post, this will do it (tested and works for me):
delete term from wpterm_taxonomy term, wpterm_relationships rel
where term.term_taxonomy_id = rel.term_taxonomy_id and rel.object_id IN (1) ;
And obviously replace the ‘1’ there with how you’re selecting the post ID’s
I would strongly recommend you test this before running it with e.g. this query which will show which terms will be deleted before you do it! And take a database backup before you’re doing large deletes in case something goes wrong 😉
select term.term_taxonomy_id from wpterm_taxonomy term, wpterm_relationships rel
where term.term_taxonomy_id = rel.term_taxonomy_id and rel.object_id IN (1) ;
Again replace ‘1’ with however you create your list of post ID’s
Related Posts:
- WPDB Insert or if exists Update
- Display data from a non wordpress database on a page template
- Inserting Post Meta From SQL
- How to execute mulitple statement SQL queries using $wpdb->query?
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- wpdb_prepare with multiple or condition
- Create table from array with prepare
- What does wp_term_taxonomy.parent reference?
- WPDB SQL query with prepare() returning variable, not db value
- What is the purpose of the “term_id” column in the “wp_term_taxonomy” table?
- How to delete a particular row in a database table
- Getting value from database table depending on field value
- Help posting values to DB on submit using $wpdb->query
- 2 $wpdb queries causing error Table ‘wp_postmeta’ is specified twice, both as a target for ‘UPDATE’
- Correct and secure way to access a custom SQL database in a custom PHP template file
- How to get specific table by current user login
- How to make a term belong to multiple taxonomies?
- What is “Advanced” SQL?
- Oracle SQL query for Date format
- Using wpdb to connect to a separate database
- get_results using wpdb
- $wpdb won’t insert NULL into table column
- Get error messages when $wpdb->insert() returns false?
- Detecting errors generated by $wpdb->get_results()
- Does dbDelta delete columns as well?
- wpdb update add current timestamp not working
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- WordPress Unit Testing – Cannot Create Tables
- How to define composite keys with dbDelta()
- Does wpdb add considerable overhead on queries with large result sets?
- Why does $wpdb return strings for mysql integer values?
- $wpdb->prepare() warning in WordPress 3.5
- Where are image paths to product category images stored in WordPress database
- Slow wp_term_relationships query
- Sharing database for collaborative development
- Inserting data into custom tables
- Hook into $wpdb
- How does $wpdb handle COUNT(*)
- Organizing WP Pages based on old website database
- How are terms connected with posts in database?
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- WordPress database error: [Query was empty] [closed]
- Export wordpress table to excel
- How to close wpdb connection? [duplicate]
- Why does dbDelta() not catch MysqlErrors?
- Connecting to external oracle database
- Bulk Update of Custom Post Type Post Status through SQL
- How do I add indexes to WordPress Database?
- Moving an entire wordpress site from one domain to a new domain and database
- Is altering a default WordPress database table update safe?
- Change SQL get_results to search for posts with custom term in custom taxonomy
- Can’t save ajax value to database
- What causes the “max_user_connections” warning on WordPress frontend?
- $wpdb variable throw this error Call to a member function get_results() on a non-object in
- Updating all rows of table with $wpdb
- Block search SQL from happening
- WPDB: how to get the value of a field in a custom database table
- wpdb query on custom table not working [closed]
- What are terms and taxonomy, how they related to post and how these three are stored in database?
- Safe way to find last inserted id in a table?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Is $wpdb->prepare escaping to much? How to use it properly?
- Filter WordPress posts by between parameter
- Database slowdown after update to 3.4.1
- orphaned taxonomy terms remove by sql query
- When and why should I use $wpdb different return types?
- Query WordPress database by registered date and role
- How wordpress accesses its own database
- Using table lock with wp_insert_post?
- Remove database entries where post_date > expiration date
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- Scheduling posts in database
- Size article thumbnails and retrieve them directly from database
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Get data from database using $WPDB
- How to use a different database to list and manage comments in the backend
- Getting all the users who have author privilege
- Multiple postmeta with same name for one post in wp_postmeta table
- WP Database Table to CSV file
- Cannot update custom database table row
- Show last modified date of database
- Uppercase to sentence case for post titles
- $wpdb->insert is not working
- SQL Error wp_commentmeta – incorrect table definition
- Extracting the post_id via the wp_insert_post action (external db query)
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- In what part of the WordPress core does the users table and usermeta table get joined?
- WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another
- Modify Database in Multi-Site wp_usermeta table
- get_tags() return an empty array after added tags with wp_insert_term()
- How do I get the posts within a certain year/date(with sql query)?
- Multiple wp_options tables to share content across installs
- Advanced SELECT query with condtional statements
- $wpdb doesn’t like to store arrays
- Select two sums with single get_var statement
- Export / import WordPress database
- WordPress choose wrong database
- WordPress is not creating table in database after activating plugin,
- Bulk-create posts from SQL database