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

learn more… | top users | synonyms

1
vote
1answer
162 views

How to best delete orphan wp_postmeta

I'm in the middle of doing some fairly complex queries involving metadata from a custom post type. Unfortunately if any posts are deleted the metadata stays put which complicates matters as I am ...
1
vote
2answers
458 views

How to write: $wpdb->update having WHERE NOT value pair in the array

I need to update all meta keys in the postmeta table that have a value other than 0, to the value of 0. I tried this.. no love (though I cannot figure out why....): $status = $wpdb->query("UPDATE ...
1
vote
1answer
107 views

wpdb query problem to access previous 3 days posts

I am trying to get all published posts titles by author id 2 most recent by post date for the last days. Here is my query: "SELECT post_title FROM $wpdb->posts WHERE post_status = 'publish' AND ...
1
vote
2answers
237 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' => ...
1
vote
0answers
106 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
37 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
0answers
338 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 ...
1
vote
1answer
255 views

Wordpress choose wrong database

I have 2 databases. When I include the database connection (with a include('filename.php');) wordpress acts really strange. I can't login, the wordpress username and password is right but it tries to ...
1
vote
0answers
34 views

Code only works every other time its run

This code below works fine as long as I leave the $wpdb query commented out. However, I'm trying to clear the current settings before I write the new ones into the db. That's the purpose of the $wpdb ...
1
vote
0answers
150 views

Query most popular terms by taxonomy over 2 week period

I have written SQL for a query that pulls the most used taxonomy terms for selected taxonomies that are published, do not have a parent post are not in a comma separated list over the past two weeks ...
1
vote
0answers
137 views

wpdb updating record in wordpress with json adds extra array elements

This is killing me - I keep getting magical array elements added to my updated array in WP. For example if my query is (var_dumped below): string(70) "UPDATE wp_mytable SET already_played = '[9]' ...
1
vote
1answer
265 views

Which action does wp_update_user triggers?

I am working modifying an ecommerce plugin, and it makes uses of wp_update_user() function, and everytime the function runs another table (created by the plugin), gets updated too. The problem is that ...
1
vote
2answers
57 views

plugin code is pulling information from database in one instance and not in other. What is wrong?

In my plugin code, I am pulling the table id from two tables. The id is being pulled from one table but not from the other and I get errors in both instances. The queries work on mysql when I use ...
1
vote
0answers
160 views

How to display users with posts published between two dates (Sorted by Post-Count) [Multisite]

I'm trying to make a list of users who have published posts within two given dates. My attempts using WP_User_query just work for one blog ID and takes time to load because it runs through a lot of ...
1
vote
1answer
640 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: ...
1
vote
1answer
633 views

Programmatically Creating Page using $wpdb and getting 404 error

EDIT: Turns out I had a permalink issue that was causing the 404 error. Original Posting below: I am creating a page programmatically using $wpdb->insert() and the resulting page returns a 404 ...
1
vote
1answer
580 views

$wpdb not being defined in function: Fatal error: Call to a member function query() on a non-object

For some reason the $wpdb object is not being defined in one particular function. I have four other functions in the file that are using $wpdb and all are working fine except this one simple delete ...
0
votes
2answers
531 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 ...
0
votes
1answer
259 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
61 views

Accessing two databases wordpress

I'm trying to access a second database with my wordpress system. To do this, I've attempted to follow the advice found here which seems to have worked for a lot of people. In summary, I'm adding ...
0
votes
2answers
230 views

How to obtain a reference to $table_prefix in $wpdb object

I need to call the WordPress options table and pull some data. However, the table name may be different (typically wp_options) depending on whether the default table prefix was used on installation. ...
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
88 views

How to return number of found rows from SELECT query

I wrote a function which is supposed to return the number of rows found in a SELECT query but it always either seems to return 0 or an array. I have been messing around with this for about an hour now ...
0
votes
2answers
102 views

Replace Main Query With Custom Query

I want to replace the main query with my own custom query. The thing is I don't want to go through the hassle of manual paging. I know there's a filter posts_results but I'm not sure how to use it ...
0
votes
1answer
50 views

PHP Fatal Error - $wpdb a non-object?

I'm getting many Fatal errors like this in Wordpress 3.6.1, multisite with Buddypress: PHP Fatal error: Call to a member function suppress_errors() on a non-object in ...
0
votes
1answer
180 views

after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()

after wordpress update to 3.5+ i get many errors in this plugin. i found that the reason is: http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/ I do not ...
0
votes
2answers
153 views

WPDB SQL query with prepare() returning variable, not db value

I have been trying to get this to work for awhile now and I cannot seem to get any farther on my own. It seems to work fine as a normal SQL query but not within the WP framework using prepare(). ...
0
votes
1answer
694 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: ...
0
votes
2answers
186 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 ...
0
votes
1answer
2k views

$wpdb->get_var not returning a result

I launched mysql and confirmed this query returns a result: mysql> SELECT * FROM wp_posts WHERE post_parent = 68 AND post_type = 'attachment' AND post_name = 'side-logo-auto2' LIMIT 1; 1 row in ...
0
votes
1answer
356 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
1answer
423 views

Wordpress db prepare

I am not trying to use $wpdb->insert, but prepare. Insert method will have one query string and an array which includes # of data which is not defined but will be defined for each query string ...
0
votes
1answer
217 views

Why does this WPDB code throw an empty WPDB error? [closed]

I'm writing a feed reader plugin for wordpress. I'm seeing a DB error that I can't figure out. First I create a table called user_entries. Then I put a sample entry into that table. When I try to ...
0
votes
2answers
322 views

wordpress $wpdb works only once

I am working on a plugin that needs to run many different queries. I created a class that has many functions and all these functions runs different queries. A DAL basically. Now when I call these ...
0
votes
1answer
449 views

$post not working working in AJAX plugin with custom post type

I am trying to create a plugin that can relate two posts to each other, and to do so I am trying to use AJAX, but I am having trouble getting the current posts ID using $post->ID. I am trying to ...
0
votes
1answer
1k views

Join inside a wpdb query.. confused!

I need to get a return from a query that provides me with email, username or nicename as well as post title based on author id. The query is to run once daily via cron and look for posts that have ...
0
votes
2answers
1k views

How to test the outcome of a wpdb query?

I want to get all the data with the meta key of "project_id" from post meta table. I wrote a query, it should work in thoery, but I have no way to see what I get, and inject this query to my plugin ...
0
votes
1answer
5k views

Should I use wpdb prepare?

I'm new to SQL and am wondering if I need to use wpdb->prepare for the following query to a table I've created global $wpdb; $tablename = $wpdb->prefix . "my_custom_table"; $sql = "SELECT * ...
0
votes
2answers
2k views

Use mysql_query instead of $wpdb query

I have a custom table inside my wordpress database called test. What if i query this table using mysql_query() instead of using for example $wpdb->get_results() Will this affect my performance? Ty ...
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. ...
0
votes
2answers
901 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 ...
0
votes
1answer
16 views

$wpdb prepare issue with mysql DATE_FORMAT

Today, I have a issue in $wpdb. I used $result = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_FORMAT(report_date, '%d-%m-%Y') FROM table WHERE report_id = %d", $report_id ) ); ...
0
votes
1answer
21 views

how to get db values without using an loop with wpdb->get_results()

So I want to return the data from 1 row from my custom DB table, but I dont want to use a loop as I only need the values once....so is there a way to do this? $results = ...
0
votes
2answers
54 views

Inserting data into `post meta` table?

How would I be able to insert data into the post meta table? I know how querying and wpdb works but I have no idea how I can just insert it into the table. I have these two fields I want to insert ID ...
0
votes
1answer
38 views

Are term_taxonomy_id and term_id the same?

I have a custom query where I need a JOIN because I want to COUNT all the posts of a specific category. So I checked the tables and I found out that table wp_term_relationships contains a reference ...
0
votes
1answer
48 views

What's the purpose / logic of split_the_query in WP_Query->get_posts

In the get_posts method of WP_Query, there's a section relating to split_the_query The logic of split_the_query is $split_the_query = ( $old_request == $this->request && ...
0
votes
1answer
80 views

insert image alongwith with custom data via a frontend form

I use wordpress as a cms. I wanted to insert custom data via a form from the frontend in my wordpress site and then echo it on a page somewhere. After learning from here and there I am able to put ...
0
votes
1answer
33 views

Create new database through static page code

I want to create a new table in current database of word press through create a static page. I write code for this as below, but there was no result. Why is that, and how can I get this right? ...
0
votes
1answer
53 views

How to stop $wpdb from prepending database name

When I run an UPDATE query using $wpdb, WP prepends the database name associated with the WP installation to whatever is passed in the table name argument. This isn't desirable as my app passes the ...
0
votes
1answer
73 views

$wpdb - joining shows no result

For one of my client's WP site, I'm making a plugin, where I'm using the db Query. I've two custom tables dedicated to the plugin: user_req — stores user chosen posts along with some custom ...