Many people asked me about fetching data from wordpress database with simple database query. Is this facility provided by wordpress API. Yes, that is provided by wordpress api. You just need to use the get_results() method.
Here I am going to give some example about using the custom sql query in wp_query method.
You need to define the gobal $wpdb variable that important in your code. here is working example for fetching the posts.
global $wpdb; $querystr = "SELECT wp_posts.* FROM $wpdb->posts wp_posts, $wpdb->postmeta WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC LIMIT 10"; $pageposts = $wpdb->get_results($querystr, OBJECT);
For fetching the Admin or user information thorough query use following code. following code is useful for fetching the single record or row.
$querystr = "SELECT wp_users.* FROM $wpdb->users WHERE wp_users.user_email = 'info@domain.com' "; $userinfo = $wpdb->get_row($querystr);
For detail information you should use the following URL:
http://codex.wordpress.org/Function_Reference/wpdb_Class

Using custom sql query in wp_query function
Incoming search terms:
- wp_query sql
- wordpress wp_query sql
- wordpress plugin api sql query
- wordpress interface to query sql database
- wp_query custom sql query
- wordpress wp_query using sql
- wp get sql query
- wordpress wp_query custom search
- wordpress use sql
- WP_Query search
- wordpress wp_query using custom sql
- wordpress paged sql query
- wordpress custom sql query
- custom SQL in wp query
- how to use my custome sql to query post in wp
- inserting sql function in wp_query
- sql function on wordpress
- sql query for search term wordpress
- sql query to get custom menu wordpress
- themes wordpress sql






useful tip for wordpress plugin developer
This post makes a lot of sense !
Nice post! You truly have a wonderful way of writing which I find captivating! I will definitely be bookmarking you and returning to your blog. In fact, your post reminded me about a strange thing that happened to me the other day. I’ll tell you about that later…
I’ve been checking your blog for a while now, seems like everyday I learn something new
Thanks