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

learn more… | top users | synonyms

1
vote
3answers
28 views

How to fetch an array in $wpdb?

I have a snippet that will select a data from database table. But I encounter an error: Warning: Invalid argument supplied for foreach() I encounter a new error: Notice: Trying to get property of ...
0
votes
2answers
32 views

WPDB Placeholders and second argument for prepared statements

How can I set placeholder and second argument for that kind of sql prepare $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID IN ...
0
votes
2answers
9 views

$wpdb->last_error deosn't show the query on error

I am inserting data in the custom table using the $wpdb->insert. However, upon error I don't seem to get any information from $wpdb->last_error. What could be the cause of this? I already have ...
0
votes
0answers
16 views

Custom database query with accents returning no results

I have an issue where using accents in my custom database query (wpdb) returns no results. $wpdb->get_results( "SELECT * FROM table WHERE city = 'Montréal'" ); Returns nothing, while ...
0
votes
1answer
10 views

Exclude category from DB query

I have next code: $drivers_all = $wpdb->get_results("SELECT DISTINCT meta_value FROM wp_postmeta WHERE meta_key = 'driver'") With this one I get the values of all fields “driver”. How can I ...
0
votes
1answer
13 views

How to use prepare to query with variables

Trying to write a prepare statement that works. This works: $countthem = $wpdb->get_var( "SELECT COUNT(*) FROM wp_cmapg WHERE lang = 'yes'" ); This does NOT work: $countthem = ...
0
votes
0answers
17 views

Use $wpdb->get_results with filter based on array

I need to filter my SQL query (in a plugin) based on an array of meta_values. I have CPT-A which is related to CPT-B. I am keeping an array of CPT-A ids in meta_key afz_entry_tags of CPT-B I need ...
0
votes
1answer
12 views

wpdb get posts by taxonomy SQL

I need a list of posts of a specific post_type plus the name of a custom taxonomy term. This is what I got so far SELECT p.post_name,t.name as clientName FROM $wpdb->posts AS p, $wpdb->terms ...
1
vote
1answer
27 views

Undefined offset: 0

Here is my PHP function function getUserIDandPush($ul){ global $table_prefix; // Prefix for Database table global $user_login; global $wpdb; // Wordpress WPDB database method $dt = ...
2
votes
3answers
105 views

WP DB Error max_user_connections

I'm currently getting this error in the front-end only (not inside /wp-admin): Warning: mysqli_real_connect(): (HY000/1203): User xxx already has more than 'max_user_connections' active connections ...
0
votes
0answers
21 views

Limit results of custom query to current category

I have created a geolocation system for a custom post type of services and have been working on a query to limit the results based on address/distance entered by the user. Everything seems to be ...
-2
votes
1answer
24 views

wpdb related question

In WordPress documentation, it says: (https://codex.wordpress.org/Class_Reference/wpdb) SELECT a Variable The get_var function returns a single variable from the database. Though only one ...
0
votes
2answers
20 views

Mowing site to another domain in simplest way

I need to move my simple Wordpres site from www.mysite.oldplace.com to www.oldplace.com in most as possible simple and native way. My simple site specification: WP 4.4.2 Twenty Twelve 1.9 theme ...
0
votes
0answers
22 views

update query wordpress plugin

I am trying to update data in wp table. However, data is not updated. This is what I've tried. Here , $eadate is DATE , $estime is time in HH:mm:ii format. <?php global $wpdb; if ...
0
votes
0answers
17 views

Why Do I Still Getting Duplicate Rows in SQL?

I'm creating a Custom Freight System which stores the order and the products requested by the user into the WordPress Database. The Problem When I insert the product into the wp_my_custom_products ...
0
votes
2answers
56 views

Wordpress wpdb->insert returns int(0) => doesn't insert anything, no errors!

I am really clueless. I want to do an insertion in my WordPress plugin the problem is it doesn't return any errors nor it insert the stuff! I don't know how to fix this and really need your help. In ...
4
votes
1answer
66 views

Wordpress Unit Testing - Cannot Create Tables

I'm using PHPUnit to Unit Test my WP plugin on top of the WP testing suite. Everything works fine except that when I try to create a table via the setUp method, the table doesn't get created. Here's ...
0
votes
0answers
33 views

Change MySQL PDO connection to a WPDB connection

So I have an autofill search box with a PHP script that gets data from the DB. It uses a PDO connection, and it works perfectly even with my Wordpress Database, but since I'm not sure of how PDO ...
1
vote
0answers
24 views

Connect to separate database using $wpdb and authenticate user

Have a couple questions. Just to get everyone up to date: I had created a new file wp-custom-config.php Use define define( 'NEW_HOST', host name); and other details. And add code for DB connect like ...
0
votes
1answer
38 views

I have include wp-config, should I add global $wpdb also?

Usually, In my wordpress website, when I modify template page file, it is done by only add global $wpdb for databse operation without including wp-config file. Now, I create my own php file in ...
0
votes
0answers
25 views

WordPress database error:

Thank you in advanced for any help on this issue. I have this query: $query = $wpdb->update($tablename, array( 'student_first_name' => ...
0
votes
5answers
80 views

Cannot access the thumbnails of attachment images… Cannot find the reason

I have a custom form that allows users to make posts and also upload images with it. The images are saved in wp_posts as post_type = attachment with a guid to show the image. Now I have created a ...
0
votes
1answer
25 views

How To Use WP_Query To Get The Custom Post type Posts With Keywords

I want to query with keywords and display some related posts on custom taxonomy page, the related posts comes from a custom post type "gift". I have tried the code below, but it only worked for ...
0
votes
1answer
14 views

Filter authors on meta value

I have added a section to my user profiles called ArtistCategory. This can be value X or Z. I'm using the code below to get a list, which I use in a menu and show after the artists display_name the ...
0
votes
1answer
23 views

DBDelta: “table doesn't exist” for a table that was just created

When I run the following code: global $wpdb; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); $table_tags = $wpdb->prefix . "tags_tb"; $sql = "CREATE TABLE $table_tags ( ...
0
votes
0answers
23 views

Trying to write a count function for a custom db query

I'm trying to tally results from a column in my dp for specific intervals (i.e. one day, two, etc..) I'm not a coder by any means, I've got the query down okay but can't get num_rows to work and then ...
0
votes
1answer
25 views

Data inserted by wpdb insert is different than data pressnt in database.

I have made this insert query: $insertsuccess = $wpdb->insert( 'compservices', array( 'orderId'=> $orderID, 'orderedTime' => $date, 'useremail' ...
0
votes
1answer
24 views

$wpdb query for price in custom field value

A classifieds list site have only 3 criterias when searching products: the common search, category and region (for ZIP, city or full address) It's not enough and I really need to include a basic price ...
0
votes
1answer
20 views

Include post_status check within $wpdb query

I've got a function that returns a count from the database for publish posts that match the product ID to the post meta ID (both are the product type). I've realized this query returns unpublished ...
0
votes
0answers
22 views

log in form using a separate database

in the html code i have made this form: <form action="http://www.mySite.co/login.php" method="post"> <fieldset> <p><input type="text" name="uname" placeholder="Name" ...
1
vote
0answers
30 views

How to translate this mySQL query to $wpdb query

I'm having trouble recreating a query from straight mySQL to $wpdb compatible. SELECT meta_value FROM `wp_postmeta` WHERE meta_key = 'review_rating' AND meta_value = 5 AND post_id IN ...
2
votes
1answer
38 views

WPDB Multiple site's posts and get featured images

I am using the code below to query 5 Wordpress sites for their posts, merging them into an array, sorting the array by date, and then displaying them: //SITE 1 $mydb = new ...
1
vote
0answers
34 views

Optimizing Wordpress Queries - Removing Group By ID

I'm looking to transform a few queries that I'm running through get_posts into direct MySQL queries, in the hopes of optimizing them further. I see that my initial get_posts query, once built and ...
0
votes
0answers
19 views

Processing a lot of $wpdb isn't insert all the data

In my plugin the user provides some CSV files that are processed and either inserted or updated based on a sku (which acts as a foreign key to my DB and a primary key for where the CSV comes from). I ...
1
vote
2answers
43 views

Wordpress SQL Issue not returning correct reselts

So, I have been working on an SQL query involving the users and usermeta tables in wordpress. I am not getting the correct results. I have the following query written SELECT * FROM ...
1
vote
2answers
42 views

$wpdb select all meta for each post

I'm running the following query trying to get the data and associated meta data of a huge number of posts: SELECT wp_posts.post_title, wp_posts.post_date, wp_posts.ID, wp_postmeta.post_id, ...
0
votes
2answers
31 views

wpdb get_row database query inquiry

Is this the right way to use get_row with a select *? $_crds = $wpdb->get_row($wpdb->prepare(" SELECT * FROM `mailers` WHERE `id` = %d", $_GET['caId'] )); $_zipcodes = $_crds->zipcodes; ...
0
votes
0answers
72 views

Wpdb insert with special characters

I am facing a strange issue with insert query using $wpdb. I am trying to insert a record below (a row from a CSV file): Plenty Denim ...
0
votes
1answer
29 views

Does WordPress $wpdb functions wait when table is locked?

Does WordPress' $wpdb functions wait when the table is locked? For example Function A() uses $wpdb->getresults. When $wpdb->getresults wants to read a table and its locked, does it wait for ...
0
votes
0answers
12 views

WordPress Plugin error: Multiple primary key defined

Given an SQL statement like this to fire on plugin activation: $charset_collate = $wpdb->get_charset_collate(); $sql_fields = "CREATE TABLE wp_my_table ( id int(11) NOT NULL AUTO_INCREMENT, ...
0
votes
0answers
36 views

Convert $wpdb to WP_Query()

I have the code below which I would like to change into a WP_Query so that I can easily filter posts by taxonomies. I am having trouble understanding how I would add get_posts_by_author_sql( ...
0
votes
1answer
74 views

wpdb get_results() returns only 2 rows

I am trying to create custom admin widget to present how many users has registered within last days. I have created function as below: function mdbootstrap_add_dashboard_recent_users(){ global ...
0
votes
1answer
54 views

WPDB - Read and write value from / to database

I have a custom field in usermeta called vatnumber. If the field has a value, how do I read that specific value for user X? Here's what I have so far: <tr class="vatnumber"> ...
0
votes
0answers
49 views

Can't Install WordPress (local) Failed to open file wp-includes/wp-db.php

Title kinda says it all. Trying to install WP locally and I get the following error when trying to use the wp-config.php generator UI: Warning: mysqli_real_connect(): (HY000/2002): No such file or ...
0
votes
2answers
51 views

Missing argument 2 for wpdb::prepare() [duplicate]

I am working on a website that uses a previously developed image slider plugin. I had it all working in my local environment but once I took it live it kicked the following error anywhere the image ...
0
votes
1answer
60 views

WP Database Table to CSV file

I'm working on creating a script that takes a custom WordPress database table and exports it into a CSV file. I cannot seem to get it to work. Can someone help me out <?php $parse_uri = explode( ...
4
votes
1answer
57 views

How to define composite keys with dbDelta()

I am getting error while trying to create a table with dbDelta() and composite primary key. The sql is pretty straight forward. $sql = "CREATE TABLE {$wpdb->prefix}voicemail_call ( user_id ...
0
votes
1answer
56 views

Dynamic URL, not a physical page within the database

Knowing how WordPress essentially processes page requests (through index.php and .htaccess), I'm trying to figure out the best way to "ignore" a certain permalink structure, or rewrite it in such way ...
1
vote
1answer
36 views

Getting id of poll from WP database

So I have a php statement: $latest_pollsid that contains a number which increases by 1 every time a specific form is submitted. I am reading this statement into several functions and for one of these ...
0
votes
4answers
59 views

wp_posts table: safely remove unused columns to save database storage

i search about it on google but didn't find any thing. I want to remove my wordpress wp_posts table's unused columns, to save my database storage... I know if table column is empty it will not ...