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
- Get error messages when $wpdb->insert() returns false?
- Does dbDelta delete columns as well?
- How to fetch Data in WordPress using MySQLi or $wpdb
- How to define composite keys with dbDelta()
- Does wpdb add considerable overhead on queries with large result sets?
- $wpdb->prepare() warning in WordPress 3.5
- Hook into $wpdb
- How are terms connected with posts in database?
- Connecting to external oracle database
- Bulk Update of Custom Post Type Post Status through SQL
- How do I add indexes to WordPress Database?
- Can’t save ajax value to database
- $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
- What are terms and taxonomy, how they related to post and how these three are stored in database?
- Is $wpdb->prepare escaping to much? How to use it properly?
- Remove database entries where post_date > expiration date
- Scheduling posts in database
- Size article thumbnails and retrieve them directly from database
- How to use a different database to list and manage comments in the backend
- Uppercase to sentence case for post titles
- $wpdb->insert is not working
- 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
- Bulk-create posts from SQL database
- Is there a WP function to get taxonomy name from taxonomy_term_id?
- $wpdb->insert Giving duplicates
- Which data is written and stored in the database when read-only (non-posting, non-commenting) users visit the site?
- I’m not able to get access to $wpdb [duplicate]
- List of ways to access WordPress database?
- Is it possible to have more than 1 MySQL database in my WordPress blog?
- How to fetch records from database WordPress
- Best practice to import user base (subscribers) from one website to another?
- AJAX wp-mysql running too slow
- Why does changing Database Table Prefixes result in loss of content?
- Connecting to a different database
- Options on how to Display member specific data from a MS SQL database
- Delete/Replace words from X to Y in post content
- Query Column of Specific ID from Database Table
- How to create more than one new wpdb object?
- Update multiple rows in one query
- How to connect and insert data in database of wordpress?
- Should I use an additional column in the DB?
- $wpdb->get_var – What value is returned when zero records are found?
- access JSON results from wordpress database with wpdb
- WordPress SQL – How to Check for Category?
- wpdb->insert not inserting first variable
- How do I have a user upload a blog post and then retrieve that to display in a card on the site?
- get value from ‘terms’ table
- custom tables in wordpress Database? (can i just create them with sql?)
- Accidently changed the GUID
- wpdb Insert unknown post data dynamic foreach loop
- How do I get database rows from a custom table using wpdb?
- Deleting empty meta key values
- Save queried result into database
- Help with $wpdb on custom code
- “BS_” rows in postmeta table
- I want to get term by term_name without taxonomy
- How to rerieve comments and their replies from DB
- What’s the easiest way to connect external database and display data on wordpress?
- How to set posts to draft in bulk based on the content of the post
- How to create index (sql) to a meta_key?
- $wpdb not working
- How To connect to the same WordPress database with different database user
- Accessing content from third party as native posts in WordPress
- WordPress character set issue
- Call to a member function insert()
- I have include wp-config, should I add global $wpdb also?
- Can’t Install WordPress (local) Failed to open file wp-includes/wp-db.php
- Link wordpress with a SQl + MongoDB + .NET
- Pulling values from a sepcific row in table
- How to add data from wordpress tables to new database tables you have created
- Creating Tables in WordPress Database
- Inserting into data into external DB using WPDB
- Install WordPress with SQL database
- Insert Extra fields added in the front end registration form to DB
- How to use remote db tables in current config? [duplicate]
- export individual posts to text files or a single csv file
- $wpdb->insert not working for last select option
- $wpdb->prepare returns empty array
- SQL query to rewrite all media URLs to end with .webp
- Weird WP -Cli Error Connection Refused