The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database
1
vote
3answers
930 views
Help With MySQL to WPDB Query Conversion
I have a problem. I've got a PHP script that tracks individual file downloads, and I'm looking for a way to display that number in individual posts. I've got a half-baked solution- a plain ol' MySQL ...
0
votes
1answer
34 views
Mysql query and odd results
I've a query here :
$sql = "SELECT ID,post_title,post_content,post_date,post_type
FROM {$wpdb->posts}
WHERE post_content LIKE {$stuff}
AND post_status = 'publish'
AND post_type = ...
0
votes
3answers
175 views
Insert Extra fields added in the front end registration form to DB
I have added some extra fields like first_name,middle name,last_name etc into the custom registration form. I want to add those details int the DB also. Now only username,email,Display name and ...
0
votes
0answers
34 views
Not Creating New Database Table [closed]
I've successfully created tables with previous plugins I've messed around with, but I can't seem to figure out exactly what's wrong with this. Hopefully it's an easy fix.
//CREATE ...
0
votes
0answers
37 views
I am trying to send ajax collected data to the current users database
I am using WooCommerce and added an additional field "location_gps" to collect the location (lat,long) added the ajax call to collect the data. Now I'm stuck getting the data into the current users ...
0
votes
1answer
35 views
Using $wpdb to update current post
I have a function that expires posts on a date, and adds a check to the database. Now, I'd like the ability to "recycle" those posts with new expiration date, but in order to do this, I need to erase ...
1
vote
1answer
329 views
passing variables as parameters to stored procedures via wpdb from php-script
i am having a slight problem with passing php-variables to a stroed procedure call from a php-script. Here comes the details:
This is how it works very perfect - passing the params as string:
...
0
votes
1answer
93 views
Select From wpdb - Author/User Directory page
I am working on a wordpress site where I have created a directory page(authors.php) that lists all users and certain author meta.
It works fine however I am trying to figure out how to only show ...
4
votes
1answer
175 views
find a random blogid across my multisite network that has at least one post published
I need to find a random blog across my multisite network that has at least one post published of a certain post_type, and return its blogid as a variable so I can use it in a switch_to_blog() call.
I ...
0
votes
1answer
2k views
Retrieving custom fields with $wpdb->get_results
I'm trying to use $wpdb->get_results to retrieve an array of all posts including custom fields. I can retrieve the meta_key and meta_value columns like this:
[meta_key] => state [meta_value] ...
0
votes
1answer
20 views
Cache metadata for set of posts
I have a query that can only be done using straight SQL, but I need to loop through the returns as a set of posts. As I understand it, WP_Query automatically gets all the metadata for all the posts ...
0
votes
2answers
85 views
wpdb-> not adding prefix to custom table
I know it should work with custom table and I think it worked in previous development I believe. But this time I don't know whey it is not getting custom table with $wpdb->tablename
Code:
global ...
1
vote
2answers
68 views
What is wrong with this wpdb update?
I've read a lot of documentation tonight, can't see why this isn't working. Obviously something I'm missing.
$newstr = "18,19";
$defid = 1;
$table = "wp_tablename";
$data = "array( 'somecol' => ...
0
votes
1answer
589 views
$wpdb->num_rows doesn't work
I'm trying to perform some checks on custom fields before they are saved on a db. So I decided to use an add_filter as it does this between browser and db. Here is my code
function ...
0
votes
1answer
36 views
Help with Related Posts Function
I'm trying to write a function that will grab all related posts according to the term of a taxonomy. I'm having trouble though trying to query multiple terms.
The way I am doing it right now is using ...
0
votes
1answer
62 views
How to check for empty and not a failure
I'm querying the postmeta table to see if a url has already been entered, using this statement (where $thisLink is the url I'm checking)
$mypostids = $wpdb->get_results("select * from ...
0
votes
1answer
112 views
Creating and Using Tables in the Wordpress Database
I plan on having over 2,000 pages per subject on my WordPress website and since each subject will require custom page types I would like to create tables for each subject in the WordPress Database. ...
0
votes
2answers
108 views
How do I create a single.php for a specific category?
I am trying to create a single.php file for a specific category on my site. Instead of loading the single.php file I want WP to return that category in a file called single-category-53.php (the actual ...
0
votes
1answer
84 views
Custom counter when link is clicked in Wordpress
I would like to monitor the number of times a user clicks the hyperlink assigned with a class name link_counter. I'm using jQuery and PHP to do this, for example:
...
0
votes
1answer
59 views
Saving custom metabox data with a twist
I've got more than a few metaboxes being used with a custom post type and I'm running into an issue where my data is not being saved as expected.
Here is the relevant part of the code, and its within ...
4
votes
1answer
97 views
Custom query to get post names beginning with a digit
I'm implementing an A-Z index for a custom post type. I've got my links printing out the page and the query working for the letters. However, the numbers are tripping me up because I don't want them ...
4
votes
1answer
68 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 ...
0
votes
1answer
117 views
Wordpress SQL JOIN query
Hi
Im trying to run 2 querys in the same query call.
// send the query
global $wpdb;
$commentQ = "SELECT * FROM $wpdb->comments " . $whereClause . $orderBy;
$comments = ...
0
votes
1answer
144 views
$wpdb error (Call to a member function insert() on a non-object)
I have very few knowledge on oo php and databases, and I am simply trying to insert data in my wp_pagesvisites table but I am having some trouble with this error message.
This is my script:
...
-1
votes
4answers
106 views
Insert into db with foreach problem
I have no idea why this foreach it`s not running. When i post the article, only inserts once. Should make it at much as needed. Do you see any problem?
$array_produse = array();
for($i=1; $i<=8; ...
1
vote
1answer
309 views
How to insert data to a database table when the field is not yet created?
Supposing I have an existing table(already created in dB) that handles user-registration (a plugin) and insert data using the $wpdB->insert like this:
$success = $wpdb->insert(
...
0
votes
1answer
58 views
Why is one one of these DB query methods (using a where filter) faster than the other (a direct get_var() query)? [closed]
In this thread I presented what I thought was a good answer, and @toscho presented one afterwards which to me seemed inferior.
But after running some timed tests, my code turns out to be ...
1
vote
0answers
62 views
Changing status of Published posts which have less Content to “Draft”
function draftpost(){
global $wpdb;
$prefix = $wpdb->prefix;
$wpdb->query("UPDATE ".$prefix."posts SET post_status='draft' WHERE LENGTH( post_content ) <500");
}
...
1
vote
1answer
430 views
using $wpdb to insert a form into a post
I am wanting to take the following form, and use $wpdb to insert it into a post. I have tried reading the class reference page INSERT rows, but I don't really know what should be referenced. I am not ...
1
vote
2answers
104 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 ...
0
votes
2answers
143 views
How to pass NULL in where array for $wpdb->update
how to get results of a row with NULL element?
I have to update the row which contains only the post_id and the repeat value, 'start' and 'end' should be NULL
mysql table screenshot: ...
4
votes
1answer
130 views
What is the advantage of the wp_options design pattern?
As we all know, a design pattern that is used frequently in Wordpress' DB code is the idea of persisting data for a particular object (blog/post/comment), indexed with a particular name or key.
We ...
0
votes
0answers
13 views
Missing Argument: $wpbd->prepare on Wordpress 3.5 [duplicate]
Possible Duplicate:
$wpdb->prepare() warning in WordPress 3.5
In
/wp-content/plugins/extended-super-admins/class-wpmn_super_admins.php
called in line 90:
$networks = $wpdb->get_results( ...
0
votes
1answer
183 views
Custom query (author is post_author or meta co_author) with Pagenavi pagination
I need to create a custom query for the author archive (where the author is post_author OR is a meta co_author), and it have to work with WP Pagenavi.
The query is something like this (omitting $wpdb ...
0
votes
1answer
226 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 ...
0
votes
2answers
138 views
Speed optimization of $wpdb->get_results
I'm using this code to generate all my custom field values from all posts for custom field named "autor".
<?php $autor = $wpdb->get_results("SELECT meta_value AS autor FROM wp_posts, ...
2
votes
2answers
438 views
Query WP data with the WPDB API from outside WordPress
I'm working on a project with WP, a bit like a plugin, but not quite one.
I'm encountering an issue, when trying to include a file that contains some custom SQL functions in a class, in a completely ...
0
votes
2answers
78 views
$wpdb->prepare error after Wordpress update [duplicate]
Possible Duplicate:
$wpdb->prepare() warning in WordPress 3.5
Im facing with a error after updated Wordpress to 3.5, Im aware of error but I cant fix it.
This is code:
...
0
votes
0answers
21 views
Missing argument WPDB PREPARE [duplicate]
Possible Duplicate:
$wpdb->prepare() warning in WordPress 3.5
Problem
I got this error: WARNING: MISSING ARGUMENT 2 FOR WPDB::PREPARE(), on this function:
CODE
function ...
0
votes
1answer
101 views
Post Bulk Update
Is there any way to update all the posts at a time through query or through admin panel.
For an example i am having an 1000 posts, how to update all the posts at a time.
Thanks.
3
votes
1answer
366 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
2answers
91 views
Custom Query based on custom field of a single post
I have posts which have a custom field date in the format yyyy-mm-dd.
What Im trying to do is list all the posts for a specific year on the side of a single page based on the year in the custom field ...
1
vote
2answers
37 views
How do you use prepare when asking for a list of id's
I'm looking to get a number of records back from the database given a list of numbers and was wondering how I would use $wpdb->prepare to do this (to take advantage of the sanitising vs SQL injection ...
1
vote
1answer
110 views
MySQL Rank & $wpdb
I need a rank column in my MySQL statement, for example:
SET @rank=0;
SELECT @rank:=@rank +1 as rank, player, points
FROM my_table
Is there a way to use the above with $wpdb? WordPress doesn't ...
2
votes
1answer
51 views
How do I batch create revisions of all posts?
I cleaned up an old-site from pasted tags, manually created lists, etc, and I'd like to keep the old posts as "revisions", so we can easily "compare" with the old posts and retrieve/revert the ...
1
vote
1answer
29 views
Get a row from a separate table by matching a posts meta_key to a tables ID column
I am trying to match a posts meta_key value to a separate tables column ID and call that row/array in the single-listing.php.
I have a meta_key value that is called dot_number. The table is called ...
1
vote
1answer
175 views
Fetch array with $wpdb
I am trying to convert this code to use the $wpdb.
$data = array();
$query = "SELECT * FROM videos";
$query_exec = mysql_query($query) or die();
while($row = mysql_fetch_array($query_exec)) {
...
1
vote
2answers
38 views
queries inside of a class
I'm building a plugin and I'm quite new to wordpress I have a class what has couple of methods what should execute database queries. The class look as it follows
class MyClass{
private ...
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
0
votes
2answers
64 views
Can't get expected result from a wpdb query
Having some trouble with my first attempt at a direct DB query using $wpdb. I'm using the WordTwit plugin, and trying to retrieve the short url extension for the current post that is created by the ...

