What are WordPress orphan relationships and how to clean them?

What are WordPress orphan relationships and how to clean them?

The ‘wp_term_relationships’ table can become bloated with many orphaned relationships, especially if you regularly delete posts on your site. This is common for content sites that are not traditional blogs. Over time, thousands of term relationships may accumulate for posts that no longer exist, consuming a significant amount of database space.

To clean these orphaned relationships, you can either use our Advanced Database Cleaner plugin or run the following SQL code (used by the plugin) directly via phpMyAdmin:

				
					DELETE FROM term_relationships WHERE term_taxonomy_id=1 AND object_id NOT IN (SELECT id FROM posts)
				
			

Do you need an expert? HIRE US NOW!