• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP Bitz

A curated collection of code snippets for WordPress

  • Home
  • About
  • Blog
  • Code Snippets
You are here: Home / Archives for mysql

mysql

Get order ID, customer shipping and billing information from WooCommerce database (MySQL query)

December 28, 2021

SELECT p.ID as order_id, p.post_date, max( CASE WHEN pm.meta_key = '_billing_email' and p.ID = pm.post_id THEN pm.meta_value …

Continue Reading

Delete orphaned post meta

July 8, 2021

DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL …

Continue Reading

Get a list of orphaned post meta

July 8, 2021

SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL …

Continue Reading

MySQL UPDATE and REPLACE

October 6, 2020

UPDATE wp_posts SET post_content = REPLACE( post_content, 'http://mysite.com', 'https://mysite.com' ), guid = REPLACE( guid, …

Continue Reading

MySQL delete records in one table that do not exist in another table

April 19, 2020

DELETE FROM content_to_tags WHERE NOT EXISTS ( SELECT * FROM content WHERE content_id = content_to_tags.content_id ) …

Continue Reading

MySQL update column in one table with data from another table

April 19, 2020

update table1 t1 join table2 t2 on t2.field = t1.field set t1.field1 = t2.matchingfield where t1.whatever = t2.whatever …

Continue Reading

MySQL copy table data to a new table

April 18, 2020

CREATE TABLE backup_table LIKE existing_table; INSERT backup_table SELECT * FROM existing_table; …

Continue Reading

Find duplicates values in a MySQL table

April 5, 2020

SELECT col, COUNT(col) FROM table_name GROUP BY col HAVING COUNT(col) > 1; …

Continue Reading

Delete orphaned post meta in WordPress database

April 5, 2020

DELETE pm FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL …

Continue Reading

Primary Sidebar

Join for free!

Get free code snippets, WordPress best practices, and practical Content Marketing advice from seasoned WordPress expert Chad Butler (butlerblog):

Recent Posts

  • Notice: Function WP_Block_Patterns_Registry::register was called incorrectly
  • Use WP-CLI to back up your site
  • Bitnami WordPress Autoptimize cannot write to the cache directory
  • Create and delete WordPress sites in XAMPP with a batch file
  • How to fix “Error: MySQL Shutdown Unexpectedly” in XAMPP control panel

Copyright © 2025 · Maker Pro on Genesis Framework · WordPress · Log in