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

learn more… | top users | synonyms

1
vote
2answers
1k views

Increment value (value = value+1) of $wpdb->update

This sql query $wpdb->query("UPDATE log SET total=total+1 WHERE id='1')"); How do I turn it into $wpdb->update() statement? Ex. $wpdb->update('log', array('total'=>'total+1'), ...
0
votes
1answer
650 views

wpdb->insert multiple record at once

So after I have created the table 'settings-table' i want to add a couple of records to it. This is how I want to do it, not the best way, so I need a better way to do this because I will add more ...
0
votes
1answer
17 views

Inserting a MySQL record into a table with an array of field names and an array of values

I see this in the Codex: $wpdb->insert( $table, $data, $format ); I'm using this type of code and it works: $wpdb->query( $wpdb->prepare( "INSERT INTO `table` ...
0
votes
0answers
20 views

WPDB get woocommerce customer phone number [closed]

I have a client which wants to display a simple order form after the order has gone through and one of the fields is the phone number but it looks like Woo doesn't have it added to their order details ...
0
votes
2answers
56 views

Perform a function when a user clicks register button

I am kind of new to WordPress coding. I'm trying to edit the wp-login.php file so if a user clicks the register button, it registers the user and stores the information in a different database table. ...
0
votes
1answer
15 views

Incorrect Use of wpdb::prepare()

Not sure what I am doing wrong here. I did not write this code however I am receiving the following error in WordPress: The query argument of wpdb::prepare() must have a placeholder. This message ...
0
votes
0answers
18 views

Inserting data into custom tables

I am trying to create custom input tables to send data into custom tables on the wp database. I cannot get my script to do anything. The user will enter a type of liquor, like vodka or whiskey, ...
0
votes
2answers
50 views

Trying to Connect to different database

I want to get list of 5 recent posts from a subdomain (not multisite) to show on our main domain. Following is the code am trying to execute, but is giving the error - Invalid arguments supplied in ...
0
votes
1answer
257 views

wpdb inside foreach loop only returns first result - 2 other similar cases found

@Milo Problem solved, found spaces in the array $arrname. I was trying to get post id using post_name. First of all I stored all post_name in an array an then loop through the array to use the key ...
0
votes
2answers
18 views

WPDB Prepared Delete

I am attempting to delete a row from my DB.I am using inputs from the user and I need to be able to sanitize using the prepared statement. The query itself looks like - DELETE FROM ...
0
votes
1answer
20 views

Outputting query results

I am trying to make plugin, and i followed codex, i am not a OOP literate, hence i a blank. I tried to run this query $myrows = $wpdb->get_results( "SELECT question FROM wp_quiz" ); while i tried ...
1
vote
1answer
318 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
3answers
868 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 ...
0
votes
0answers
10 views

adding a log row log table, when the draft post publish

i wrote some codes, about wpdb update query. but update_post meta works fine but, wpdb update query doesn't. where am i wrong ? here is the code ; add_action('publish_post', ...
1
vote
1answer
173 views

MySQL LIKE not working

It seems MySQL's LIKE operator behaves like a = operator. The following MySQL query returns the expected result (1 entry): $meta_key = '_locality'; $meta_value = 'The Hague'; $post_ids = ...
0
votes
1answer
25 views

plugin ajax to external php file always return null

I am struggling with this error for a while now. The plugin inserts data to the table. Here's the code : File : plugin/_add.php require_once('../../../wp-load.php'); global $wpdb; $table_name = ...
0
votes
0answers
14 views

Output terms based on custom fields

This question is rather specific. In my custom posttype "sak", I have a taxonomy called "vvpl". This taxonomy has a custom field called "revision" because a term have copies based on how many ...
0
votes
2answers
48 views

Object method calling for global $wpdb in header.php

I am developing a Wordpress plugin in an object oriented way, and I would like to read data from the wordpress database using the global $wpdb variable. The global $wpdb variable is called from ...
0
votes
0answers
8 views

Separate Register Login

I plan to create a bespoke login and register feature on my WordPress Frontend. These users won't have access to the backend of WP. Just to a frontend area. Should i store the information submitted ...
0
votes
3answers
48 views

How to display a specific category using a custom Query?

Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below ...
0
votes
1answer
13 views

Update vs Insert logic but the last key is always inserted?

I have added a custom db table which looks like usermeta table, just storing some key - value pairs. But now i am stuck with the following logic a/ if key exist for a user use an update query else ...
3
votes
1answer
276 views

Change post status based on meta value

I have this cron set up to trash posts x days after it is posted. This works. Edit: Added my answer to my question. add_action( 'wp', 'do_trash_ads' ); function do_trash_ads() { if ( ! ...
0
votes
2answers
18 views

$wpdb->get_var multiple queries in one database check

I am using the $wpdb->get_var php code to get the first name and last name on the records, in the wp_usermeta table... But because the field value is stored in the same cell, I don't know how to merge ...
0
votes
2answers
61 views

How To Get Some Data From WordPress Database Using WordPress $wpdb Query?

I am trying to get some data from WordPress database tables in a plugin. For that, I am using the below code... global $wpdb; $findID = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_name = ...
0
votes
2answers
72 views

Call to a member function get_results() on a non-object in wordpress plugin

I am using revolution slider plugin. I got above error while executing one of my front end form. This is my code in that file.. <?php class UniteDBRev{ private $wpdb; private $lastRowID; ...
4
votes
3answers
640 views

How might I retrieve a featured post image from an external WP site and display it as a link back?

I have two WP sites. I want to reach from one of them, into the other, and retrieve specific featured images for posts, and display them with a link to that post. I am using this line (with the ...
0
votes
0answers
38 views

$wpdb->get_results(…) returns empty array despite correct query

As title implies, I cannot seem to get $wpdb->get_results to give results. Running the "raw" query is successful, but this seems to be failing for some strange unknown reason. global $wpdb; ...
0
votes
1answer
35 views

What is _transient_random_seed for?

This is a very short question. _transient_random_seed is in wp_options. What is it for?
0
votes
1answer
31 views

How can I retrieve data from alternate database using wpdb class?

I'm attempting to retrieve data from a separate WordPress installation on the same server. I'm able to use the wpdb class to successfully connect to the alternate database and get results, however, I ...
0
votes
1answer
25 views

How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?

Our plugin (VersionPress) needs to track database changes so that it can version-control them. We currently do this by creating db.php and overriding the $wpdb instance in it but it has an issue that ...
0
votes
0answers
17 views

Issue On WordPress multisite its create new table for each user

I am using WordPress for multisite all configuration are right, but it's create new table for each user like (wp_1_options, wp_2_options, wp_3_options etc for each table) it's a very big issue for me. ...
0
votes
1answer
14 views

Multi-site site nav, wpdb->prepare missing argument

I'm using a Wordpress Multi-site to house a number of sites in one WP install I'd like to have a nav showing each site with a link to the site. I'm using this function to do this <?php ...
1
vote
1answer
41 views

Wordpress SQL query - returning 'true' 'false' or 'null'

I am working on coding a PHP form for my website that requires the user to enter a code before the form becomes active. I have a field called "used" that I set up as a Boolean/TinyInt which I thought ...
0
votes
0answers
22 views

How to make iteration on wpdb->update or query statement?

I want to change post_names with iteration; I have similar post names and want to change them by foreach iteration. Initial post name is "one-book" and there are 30 similar names. I want to change ...
0
votes
1answer
26 views

Exclude specific terms from all queries using posts_where or something similar

Basically what I'm trying to do is exclude all posts that belong to a specific set of terms from showing in any and all queries across the board, EXCEPT when you're actually viewing that post or page. ...
0
votes
1answer
33 views

Advanced SELECT query with condtional statements

I am having trouble understanding the proper way to write an advanced select query. I have the following the code here. if (!empty($_GET['3321body_type'])) { $bt = $_GET['3321body_type']; ...
0
votes
1answer
23 views

At what point during a typical request does the $wpdb object become available?

I've wrote some custom SQL queries inside a class method and noticed they seem to work if I hook the method to the wp action. If I hook to the plugins_loaded action, they don't seem to work. My ...
0
votes
1answer
16 views

wp_commentdata: error in documentation?

The page http://codex.wordpress.org/Database_Description#Table:_wp_commentmeta lists the meta_id field of the wp_commentdata table as being both PRIMARY KEY and DEFAULT NULL. But a primary key cannot ...
1
vote
0answers
32 views

Codex: Database Description: meaning of Cardinality

The following post outlines how to word cardinality is commonly used when dealing with databases: http://stackoverflow.com/questions/10621077/what-is-cardinality-in-databases. However I have not been ...
4
votes
3answers
7k 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 ...
1
vote
2answers
493 views

Mysql query LIKE not working

I'm using this code. $blog_list = $wpdb->get_results( "SELECT " . $extra . "blog_id, last_updated FROM " . $wpdb->blogs. " WHERE public = '1' AND archived = '0' AND mature = '0' AND spam = '0' ...
0
votes
1answer
38 views

WP_USE_EXT_MYSQL

Here is the constructor for the wpdb class as found in the source code. According to a google search this has been recently renamed from USE_EXT_MYSQL. However I cannot find anywhere in the source ...
0
votes
1answer
9 views

wpquery properties last_query and last_result : should these be public or private?

I've come across the following lines of code in wp-includes/wp-db.php: /** * Last query made * * @since 0.71 * @access private * @var array */ var $last_query; /** * Results of the last query ...
0
votes
2answers
32 views

wp-content/db.php : where is this file?

At the top of the source file wp-includes/wp-db.php I can find the following comment: /** * WordPress Database Access Abstraction Object * * It is possible to replace this class with your own * ...
0
votes
0answers
29 views

Error establishing database connection on app engine

Error establishing database connection on app engine after deploying wordpress. I got an error Notice: Undefined property: batcache::$query in ...
3
votes
3answers
1k views

WPDB Insert or if exists Update

I'm not crazy familiar with WPDB or SQL in general but I have a custom table for my project and I'm trying to assign some metadata to it. What I'd "like" to happen is if a row exists, update it and if ...
0
votes
1answer
27 views

Display future posts in archive

I'm using the following code to display an archive of posts. <?php // Get years that have posts $years = $wpdb->get_results( "SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type = ...
0
votes
0answers
28 views

wpdb custom tables without plugin

I am using custom tables, with $wpdb, trying to perform basic queries at the moment. I can't find anything on manually creating tables then using them with $wpdb, everything is plugin related. I ...
0
votes
1answer
36 views

Ascending order of yearly archives [closed]

Hey there, I stumbled upon this question but I can't seem to contact the author, because I'm still too new here. I'm using this snippet on my archives.php page to display my posts sorted by years. ...
0
votes
1answer
26 views

Using $wpdb in a plugin, what sort of data does it return?

I have following code: <?php $q = intval($_GET['q']); global $wpdb; $myoption = get_option( 'fixformdata_options' ); $myoptionValue = maybe_unserialize( $myoption ); $result2 = ...