adsense

How to Reference the WordPress Database





1. Globalize the '$wpdb' variable before using it, using the following code:global $wpdb;
2. Write out the query or function that you want to run on your WordPress site. For now, just leave a gap at the point you need to reference the tables.

3. Fill in your gap with the relevant reference. For the Posts table, use '$posts'; for Meta Content, use '$postmeta'; for the Comments table, use '$comments'; for the additional comment information, use '$commentmeta'; for the Terms table which holds the descriptions of categories and tags, use '$terms'; for the Term_taxonomy table which holds the categories and tags, use '$term_taxonomy'; for the Users table, use '$users'; for the Usermeta table which contains nicknames, descriptions and permissions of registered users, use '$usermeta'; for the Links table, use '$links'; and for the Options table, use '$options.'
4. Add the opening '
' -- without quotes -- php tags if you have not already done so.
5. Run your code and check whether it works correctly. If the query isn't working, turn error echoing on to help you troubleshoot and fix errors in your code. To turn error echoing on, use this line of code:
show_errors(); ?>To turn error echoing off completely, simply remove the above line. To turn it off at a certain point in the code, use the following line:
hide_errors(); ?>You can then turn it back on later if needed. You can also print the errors generated by a query with the following line:
print_error(); ?>This prints the error of the most recent query.

Comments

0 Responses to "How to Reference the WordPress Database"

Post a Comment

Popular Posts

About