Podcast Episode

505 – Writing SQL to View Data in WordPress


Writing SQL to View Data in WordPress

There are four types of operations that you can do in SQL:

  • Create
  • Read
  • Update
  • Delete

Here are some examples of each:


  • SELECT * FROM wp_posts (this will select and display all items in the wp_posts table)
  • SELECT * FROM wp_posts WHERE post_excerpt = ” (this will show all posts/pages, etc that have no excerpt defined


UPDATE wp_posts SET post_status = 'draft' (this will update all posts/pages/products to draft)

UPDATE wp_posts SET post_status = 'draft' WHERE post_type = 'product' (this will mark all products set to draft)


DELETE from wp_comments WHERE comment_approved =  'spam' (this will delete all spam comments)