The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database
14
votes
6answers
10k 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
3
votes
1answer
381 views
$wpdb->prepare() warning in WordPress 3.5
I am receiving this warning when I try to run a database query:
Warning: Missing argument 2 for wpdb::prepare()
The offending query is:
$result = $wpdb->get_var(
$wpdb->prepare(
...
0
votes
1answer
230 views
Stackoverflow type of badge plugin giving warnings in Wordpress 3.5
I modified an abandoned Stackoverflow form of badge plugin to work with Wordpress 3.4.2 and it does indeed. The full script for it is here: http://pastebin.com/Ta91zXiL
When upgrading to Wordpress ...
2
votes
1answer
193 views
Get terms that contain posts that in turn belong to other terms?
So I have custom taxonomy called "shape" and another one called "color". If I want to get the list terms under shape that contain posts that are also present in terms under color, how do I do that?
...
4
votes
1answer
193 views
Query causing load because of SQL_CALC_FOUND_ROWS post counting?
I found this query causing some load in the server, my hosting provdier asked me to look on it.
SELECT SQL_CALC_FOUND_ROWS wp_posts
I think this select no. rows found in wp_posts table.. but i ...
1
vote
2answers
309 views
wpdb Custom Meta Data with 2 conditions
This is one of those problems that I've spent way too much time on, and there is probably a VERY simple solution that I am missing. Any help would be greatly appreciated.
I am trying to populate a ...
2
votes
3answers
3k views
Pagination with custom SQL query
I have my own SQL string to select Custom Post Type posts with specific WHERE clause. I've used the offset and limit to return appropriate posts depending on a page being displayed. That's working ...
4
votes
1answer
78 views
prepare() not working
When I do this:
$transients = $wpdb->get_col(
"
SELECT option_name
FROM $wpdb->options
WHERE option_name
LIKE '_transient_wb_tt_%'
"
);
It works ...
2
votes
1answer
231 views
Querying Email Addresses for a List of Users with Same Last Name?
I have a site with many users and many of them have the same last name. I want to get the emails of all the users with the same last name (IE: Smith) that has a post related to a particular taxonomy ...
1
vote
1answer
126 views
Merging PHP download script into `functions.php`
I run a large mixtape download site on WordPress. I'm currently developing a new theme and I'd like to include as much site functionality into the theme's functions.php.
For serving the downloads, I ...
1
vote
2answers
113 views
Does dbDelta delete columns as well?
I created a table using the dbDelta function and then removed a few columns and added a few. The new columns did get created but the old columns did not get deleted from the table.
Is there a ...
1
vote
0answers
180 views
$wpdb->get_results() returns good result only in first foreach iteration
I've got strange issue when I am using $wpdb->get_results() in content-single.php in Twenty Eleven theme. $wpdb->get_results() returns proper values only in first loop iteration. I've got simple ...
0
votes
2answers
223 views
$wpdb returns no results with SELECT query on custom post type, works on default post type
EDIT: Adding more background info.
I've coded a plugin that adds a meta box to the post page. When the post is published, the plugin will generate a random ID for the post, and insert the random ID ...
0
votes
1answer
264 views
SQL query not working in alphabetical post title/content search
I have an ajax request using wp_ajax sending one variable named "q" what I want to do is after the script get's the request to look inside the db and fetch the title and id of the corresponding posts ...
0
votes
4answers
647 views
Trying to display posts by authors in with specific user meta
Ok here's the solution:
<?php
$wp_user_search1 = new WP_User_Query( array(
'meta_key' => 'state' ,
'meta_value' => 'NM',
));
$listers1 = $wp_user_search1->get_results();
$lister_ids1 = ...
0
votes
1answer
2k views
$wpdb->insert - inserting multiple rows
How do I use $wpdb->insert to insert multiple rows. Here is my code.
for($i=0; $i<=$urlCount; $i++) {
$stat = $wpdb->insert(
'WP_URLS',
array(
'POSTID' => ...
0
votes
1answer
860 views
Wordpress $wpdb get posts from category and sort by custom meta
I have a custom post type of 'events' which has a meta key 'event_date'
Im using the following to retrieve those posts and arrange them by 'event_date'
global $wpdb;
$today = ...
0
votes
2answers
791 views
How to change a custom query into a standard loop?
I'm trying to modify how results are displayed in a post list that's currently controlled by the code below. However, it's not built in the WP_Query while ( $the_query->have_posts() ) : ...
