SlideShare a Scribd company logo
Saturday, March 16, 13
HI, I’M JOHN


             • Founder @ 9seeds.com

             • WordPress Developer

             • Viva, Las Vegas




Saturday, March 16, 13
The Problem
                    You’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 up
                         We 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 You!
                         john@9seeds.com - @vegasgeek




Saturday, March 16, 13

More Related Content

More from vegasgeek

Building an Autonomous Website
Building an Autonomous WebsiteBuilding an Autonomous Website
Building an Autonomous Website
vegasgeek
 
Y U No Tell Me? - WordCamp Tampa 2014
Y U No Tell Me? - WordCamp Tampa 2014Y U No Tell Me? - WordCamp Tampa 2014
Y U No Tell Me? - WordCamp Tampa 2014
vegasgeek
 
WordPress Use Cases
WordPress Use CasesWordPress Use Cases
WordPress Use Casesvegasgeek
 
Using BuddyPress as a Directory - BuddyCamp Minneapolis 2013
Using BuddyPress as a Directory - BuddyCamp Minneapolis 2013Using BuddyPress as a Directory - BuddyCamp Minneapolis 2013
Using BuddyPress as a Directory - BuddyCamp Minneapolis 2013
vegasgeek
 
An Introduction to Multisite - WordCamp Phoenix
An Introduction to Multisite - WordCamp PhoenixAn Introduction to Multisite - WordCamp Phoenix
An Introduction to Multisite - WordCamp Phoenix
vegasgeek
 
WCLV - Introduction to child themes
WCLV - Introduction to child themesWCLV - Introduction to child themes
WCLV - Introduction to child themesvegasgeek
 
WordPress meetup - 10 plugins
WordPress meetup - 10 pluginsWordPress meetup - 10 plugins
WordPress meetup - 10 pluginsvegasgeek
 
Intro to WordPress Child Themes
Intro to WordPress Child ThemesIntro to WordPress Child Themes
Intro to WordPress Child Themesvegasgeek
 
WordCamp Reno 2011 - Intro to Genesis Child Themes
WordCamp Reno 2011 - Intro to Genesis Child ThemesWordCamp Reno 2011 - Intro to Genesis Child Themes
WordCamp Reno 2011 - Intro to Genesis Child Themes
vegasgeek
 
Intro to StudioPress child themes
Intro to StudioPress child themesIntro to StudioPress child themes
Intro to StudioPress child themes
vegasgeek
 
Building your first plugin by John Hawkins at WordCamp MSP
Building your first plugin by John Hawkins at WordCamp MSPBuilding your first plugin by John Hawkins at WordCamp MSP
Building your first plugin by John Hawkins at WordCamp MSP
vegasgeek
 
Beginning Plugin d
Beginning Plugin dBeginning Plugin d
Beginning Plugin dvegasgeek
 
Using WordPress as a CMS for Affiliate Marketing
Using WordPress as a CMS for Affiliate MarketingUsing WordPress as a CMS for Affiliate Marketing
Using WordPress as a CMS for Affiliate Marketing
vegasgeek
 

More from vegasgeek (13)

Building an Autonomous Website
Building an Autonomous WebsiteBuilding an Autonomous Website
Building an Autonomous Website
 
Y U No Tell Me? - WordCamp Tampa 2014
Y U No Tell Me? - WordCamp Tampa 2014Y U No Tell Me? - WordCamp Tampa 2014
Y U No Tell Me? - WordCamp Tampa 2014
 
WordPress Use Cases
WordPress Use CasesWordPress Use Cases
WordPress Use Cases
 
Using BuddyPress as a Directory - BuddyCamp Minneapolis 2013
Using BuddyPress as a Directory - BuddyCamp Minneapolis 2013Using BuddyPress as a Directory - BuddyCamp Minneapolis 2013
Using BuddyPress as a Directory - BuddyCamp Minneapolis 2013
 
An Introduction to Multisite - WordCamp Phoenix
An Introduction to Multisite - WordCamp PhoenixAn Introduction to Multisite - WordCamp Phoenix
An Introduction to Multisite - WordCamp Phoenix
 
WCLV - Introduction to child themes
WCLV - Introduction to child themesWCLV - Introduction to child themes
WCLV - Introduction to child themes
 
WordPress meetup - 10 plugins
WordPress meetup - 10 pluginsWordPress meetup - 10 plugins
WordPress meetup - 10 plugins
 
Intro to WordPress Child Themes
Intro to WordPress Child ThemesIntro to WordPress Child Themes
Intro to WordPress Child Themes
 
WordCamp Reno 2011 - Intro to Genesis Child Themes
WordCamp Reno 2011 - Intro to Genesis Child ThemesWordCamp Reno 2011 - Intro to Genesis Child Themes
WordCamp Reno 2011 - Intro to Genesis Child Themes
 
Intro to StudioPress child themes
Intro to StudioPress child themesIntro to StudioPress child themes
Intro to StudioPress child themes
 
Building your first plugin by John Hawkins at WordCamp MSP
Building your first plugin by John Hawkins at WordCamp MSPBuilding your first plugin by John Hawkins at WordCamp MSP
Building your first plugin by John Hawkins at WordCamp MSP
 
Beginning Plugin d
Beginning Plugin dBeginning Plugin d
Beginning Plugin d
 
Using WordPress as a CMS for Affiliate Marketing
Using WordPress as a CMS for Affiliate MarketingUsing WordPress as a CMS for Affiliate Marketing
Using WordPress as a CMS for Affiliate Marketing
 

Recently uploaded

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 

Recently uploaded (20)

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 

An into to using $wpdb with your own database tables