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
- 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
- wpdb->insert multiple record at once
- How to define composite keys with dbDelta()
- Hook into $wpdb
- How does $wpdb handle COUNT(*)
- WordPress database error: [Query was empty] [closed]
- Change SQL get_results to search for posts with custom term in custom taxonomy
- 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?
- Filter WordPress posts by between parameter
- When and why should I use $wpdb different return types?
- How wordpress accesses its own database
- Using table lock with wp_insert_post?
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- How to use a different database to list and manage comments in the backend
- Cannot update custom database table row
- Show last modified date of database
- $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?
- How do I get the posts within a certain year/date(with sql query)?
- Multiple wp_options tables to share content across installs
- Select two sums with single get_var statement
- Make an Items attribute searchable (taxonomy using existing attribute)
- Update from 4.5 to 4.6 failing
- Setup private content for specific users with daily updates [closed]
- Get posts under a category with SQL
- Insert Query not working in the form
- I’m not able to get access to $wpdb [duplicate]
- Problems with moving my WordPress site to another domain/server
- Is it important to have integers inserted using %d rather than %s?
- Problem in using wpdb
- List of ways to access WordPress database?
- pull data from a remote wordpress database
- Why does changing Database Table Prefixes result in loss of content?
- Trouble running $wpdb->query() with last_insert_id
- Options on how to Display member specific data from a MS SQL database
- Using $wpdb | checking entered email against existing emails in db
- Location of WP default mySQL tables creation file?
- How to connect and insert data in database of wordpress?
- Get results from wordpress data custom table
- Outputting query results
- $wpdb->get_var – What value is returned when zero records are found?
- How to display data from db in select list [closed]
- WordPress SQL – How to Check for Category?
- add_post_meta — not working
- Select From wpdb – Author/User Directory page
- $wpdb->insert not inserting all rows
- wpdb Insert unknown post data dynamic foreach loop
- SELECT rows between two datetimes when the range is dynamic [closed]
- Deleting empty meta key values
- Insert NULL value using prepare()
- Help with $wpdb on custom code
- “BS_” rows in postmeta table
- $wpdb->insert duplicating rows
- How to rerieve comments and their replies from DB
- Can I use a wpdb object to connect to a non-WordPress Oracle database [duplicate]
- What’s the easiest way to connect external database and display data on wordpress?
- WordPress Database Query works in phpMyAdmin but not in the code
- Delete all users meta that named: user_avatar
- Using $wpdb to insert data into a table
- How To connect to the same WordPress database with different database user
- I cannot change anything in my wordpress database from within wordpress?
- Call to a member function insert()
- I have include wp-config, should I add global $wpdb also?
- Processing a lot of $wpdb isn’t insert all the data
- Can’t Install WordPress (local) Failed to open file wp-includes/wp-db.php
- get_the_terms is not working
- How to add data from wordpress tables to new database tables you have created
- Creating Tables in WordPress Database
- Getting deleted users in database
- Install WordPress with SQL database
- How to use remote db tables in current config? [duplicate]
- $wpdb->prepare returns empty array
- why you don’t Implement PDO for access every thing to database
- SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta
- Weird WP -Cli Error Connection Refused
- SQL errors when querying for something with apostrophes
- Database table prefix different between wp-config.php and in database