The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database

learn more… | top users | synonyms

4
votes
3answers
5k views

How do you properly prepare a %LIKE% SQL statement?

I'd like to use a LIKE %text% statement while still using the WordPress $wpdb class to sanitize and prepare input. SELECT column_1 from `prefix_my_table` WHERE column_2 LIKE '%something%'; I've ...
0
votes
2answers
646 views

Have working sql query… trying to adjust it to use $wpdb

So I have this code that queries a custom plugin generated table in the wp database. It works perfectly as is. But I'm trying to adjust it to use $wpdb instead of the $con function I have set up. ...
2
votes
3answers
1k views

Does a query executed through wpdb class get cached?

I am not sure how WordPress cache the queries. I had the impression that whenever I execute a query through wpdb class, it gets cached. For example, on codex under Select a Row and Select a Var, it ...
0
votes
1answer
363 views

Subdomain redirect problem

Wordpress is installed my root directory(/root/). I have a subdomain(dammani.techbrij.com) and I want to access some files of main domain from sub domain. I have done following thing: ...
1
vote
1answer
2k views

How to close wpdb connection?

Is there any method to close connection similar to mysql_close() for wpdb in wordpress? Is it not necessary to close connection for global wpdb?
1
vote
1answer
276 views

In what part of the Wordpress core does the users table and usermeta table get joined?

I have been trying to work out just where in the massive jungle of Wordpress include classes the usermeta table is joined onto the users table and if so, how does it work? The one confusing thing ...
0
votes
1answer
714 views

Ajax future single post query doesn't work when NOT logged in

I am having a problem with an ajax request for a single post, when the user is not logged in. The post is a calendar date and is in the future. the query works fine if I am logged into wordpress but ...
3
votes
2answers
947 views

$wpdb->insert is changing a value

I'm writing a plugin called 'Featured Releases' for a client. The user fills out a short form in the admin area which inserts some text and an image id into the wordpress database via $wpdb->insert. ...
0
votes
1answer
262 views

How do I query a table?

I am using Contact form 7 and the database extension, the db extension creates a table called wp_CF7DBPlugin_SUBMITS. I have 2 forms on my site, I need to know if the user has completed the 2nd form, ...
2
votes
1answer
3k views

Check for success of $wpdb->update() correctly

My code is if( $wpdb->update($tableName,array('opt_value'=>$cInfo),array('opt_name'=>'showWeatherWidget'))) //show success message else // show failure message This is not ...
3
votes
1answer
1k views

what are the differences between wp_users and wp_usermeta tables?

what are the differences between wp_users and wp_usermeta tables? i use wp-email-login plugin and i just noticed that if a user change his email in the profile page it saved in the wp_usermeta table ...
1
vote
1answer
1k views

Safe way to find last inserted id in a table?

Is it safe to use $wpdb->insert_id; to find the id of a last updated row id just after an update? ex: $sql = $wpdb->insert($table_name, $arrayWithDataToInsert, array('%s','%s')); ...
1
vote
3answers
1k views

Why would switch_to_blog stop working?

I'm using the Multisite functionality of WordPress 3.0, and I have a network of sites built where I display one random post from one of the subsites on the main site's front page. I accomplish this, ...
0
votes
1answer
431 views

Placing a widget with $wpdb query

I'm getting the feeling that adding Widgets via MySQL query is not as simple as I thought. I was under the impression all data is stored in the options table, but it seems like I was wrong. Any idea ...
0
votes
1answer
2k views

Fatal error: Call to a member function query() on a non-object

In the code below (from my functions.php), I'm attempting to create an array of items from the wp_postmeta table where the meta_key is "_wp_attached_file". I'm getting an error: Fatal error: Call to ...
0
votes
2answers
900 views

Wordpress(wpdb class) and mysql stored procedures

$query = "CALL .........."; $result = $wpdb->get_results($query); print_r($results); Is returning an empty array and $wpdb->query does not return anything, how do you run stored procedures from ...
17
votes
6answers
16k views

Using wpdb to connect to a separate database

I want to connect wpdb to another database. How do I create the instance and pass it the database name/username/password? Thanks
4
votes
1answer
4k views

$wpdb->insert() and Values for Datetime Columns?

I have a custom table with a DATETIME column. I have a function to add records; I would like to add an $expires argument to this function which can hold a unix timestamp noting when the record should ...