[wp-hackers] How to use $wpdb in plugins

Stephen Harris contact at stephenharris.info
Mon Jan 6 16:03:32 UTC 2014


If you are referring to the default database tables then there are 
functions available that allow you to add/remove/insert records. If 
these are custom tables then I typically would create functions which 
handle those operations, along with any required validation and 
sanitisation. That way any SQL statements (and the global $wpdb) are 
contained within those three (or thereabouts) functions.

On 06/01/14 15:58, Leo Baiano wrote:
> What better way to use the global $ wpdb in building a plugin? I'm working
> on a plugin and some methods need to access data in the database tables,
> including creating, and I was in doubt about the best way, like, do not
> want to quit repeating global $ wpdb in all methods of my class.
>
> How do you do?
>



More information about the wp-hackers mailing list