Saturday, March 16, 13
May 17, 2015
Saturday, March 16, 13
HI, I’M JOHN
• Founder @ 9seeds.com
• WordPress Developer
• Viva, Las Vegas
Saturday, March 16, 13
The ProblemYou’ve got database tables you
need to access from inside wordpress
Saturday, March 16, 13
What are my options?
• Convert all the data to custom post types
• Write some (potentially) janky direct database access queries in to your theme or plugin
• Or, you can check out $wpdb
Saturday, March 16, 13
What is $wpdb?
Saturday, March 16, 13
$wpdb
“WordPress provides a global variable, $wpdb, which is an instantiation of the
class already set up to talk to the WordPress database.”
Saturday, March 16, 13
Let’s dig in!
Saturday, March 16, 13
My Contacts
Saturday, March 16, 13
Some Data
Saturday, March 16, 13
First upWe need to tell WordPress
about our new table
Saturday, March 16, 13
Adding our table
Saturday, March 16, 13
Accessing our table data
Saturday, March 16, 13
get_results()
Saturday, March 16, 13
Saturday, March 16, 13
Which turns...
Saturday, March 16, 13
Into...
Saturday, March 16, 13
Adding data to our custom
Saturday, March 16, 13
Start with a form
Saturday, March 16, 13
Start with a form
Saturday, March 16, 13
Check your nonce!
Saturday, March 16, 13
... from the codex
All data in SQL queries must be SQL-escaped before the SQL query is executed to prevent against SQL injection attacks. This can be
conveniently done with the prepare method.
Saturday, March 16, 13
query() and prepare()
Saturday, March 16, 13
Our data added
Saturday, March 16, 13
This is just the beginning!
Saturday, March 16, 13
Resources
• http://codex.wordpress.org/Class_Reference/wpdb
• http://www.slideshare.net/vegasgeek
Saturday, March 16, 13
Thank [email protected] - @vegasgeek
Saturday, March 16, 13