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

learn more… | top users | synonyms

0
votes
1answer
24 views

Should I use an additional column in the DB?

I'm building a site for a client. They need a functionality where WordPress can tell if a logged in user has viewed a post in order that they might serve a notice or hide the original content. I ...
0
votes
1answer
17 views

Unknown column 'siteurl' in 'where clause' WPDB outside

I am trying to get Mysql values from outside wp. My code: define( 'BLOCK_LOAD', true ); require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' ); require_once( $_SERVER['DOCUMENT_ROOT'] . ...
2
votes
2answers
56 views

Differences between wpdb->get_results() and wpdb->query()

Who can explain me the differences between wpdb->get_results() and wpdb->query() in making generic queries to wordpress db?
0
votes
1answer
22 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
1answer
19 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
20 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
21 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
2answers
51 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
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 ...
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
177 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
29 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
52 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
9 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
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 ...
0
votes
3answers
51 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
2answers
20 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
64 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
78 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; ...
0
votes
0answers
48 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
41 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
33 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
26 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
42 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
23 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
34 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 ...
1
vote
0answers
33 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 ...
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 ...
0
votes
1answer
42 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
34 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 ...
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
29 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 = ...
0
votes
0answers
21 views

WordPress database error on a query working fine in MySQL Workbench

On activating my plugin Wordpress adds an entry to the error log... WordPress database error for query SELECT * FROM wp_c2pprojects WHERE projectid = 20 made by ...
0
votes
0answers
59 views

Add delete/edit button to each row in an SQL table (Wordpress Backend)

I have a form that is submitting entries to a table in the backend of my Wordpress installation. I would like to add edit/delete buttons to each row so that an administrator can delete submissions or ...
0
votes
0answers
19 views

Returning error with WP Insert without getting an error in error log

I'm checking if a key exists in my database using $wp_db->insert() and am executing code based on the result. I know that if a row already exists it will return false and I want to use that to execute ...
0
votes
1answer
76 views

Can't update multiple rows with $wpdb query

it seems that I cannot update multiple rows to change the post_type of posts having a specific tag. I follow different method, even if it seems the good one is this one : global $wpdb; $result = ...
-1
votes
2answers
42 views

What's wrong with my $wpdb prepare

I can't get my head around this. I get this error: Parse error: syntax error, unexpected '"' in 224. The line is this between foreach $html: $html = ''; foreach ( $recent_across_network as $post ...
0
votes
1answer
36 views

Can I use $wpdb for my custom tables in the WordPress database?

I am building a custom application based on WordPress. I have my custom tables in the WP database. Can I use $wpdb to work with them, or is that class solely for the WP related tables? For example, ...
0
votes
1answer
42 views

foreach loop inside the loop creating duplicates in output

I have a foreach loop inside the loop that is getting info from a separate table. The table has a column that has an id that reflects the id of the post type so it should always be unique. When I ...
0
votes
0answers
24 views

How to operate two wordpress databases simulataneously?

I am having a situation, where i have two wordpress sites. One is for saving the data and content and other is for showing the data/content. Now the situation is, i want a user to register on one ...
0
votes
0answers
20 views

How To Structure A Wordpress Database Query?

I have an array containing the IDs of the rows I want to update: $matches = array('abc123', 'def456', 'ghi789'); Rows with those IDs must be updated so that their 'confirmed' value is changed from ...