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

learn more… | top users | synonyms

0
votes
0answers
29 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
54 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 ...
2
votes
3answers
213 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 ...
1
vote
1answer
37 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 = $...
4
votes
2answers
454 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
0answers
22 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
26 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
21 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
31 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 (isset($_POST['...
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
0answers
200 views

$wpdb->query(update) not working as supposed when passing GET request in the where clause

I have made a table 'wp_mostfavourite' in wordpress database, it has got three fields, 'serialno', 'postid', 'counts'. The 'counts' is supposed to be increased by 1, whenever the following query is ...
7
votes
2answers
29k views

How to print the excuted sql right after its execution

I am searching for a way by which i can print the executed sql query just after the : $wpdb->query( $wpdb->prepare("INSERT INTO tbl_watchprosite ...
2
votes
1answer
49 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 wpdb('xxxx','xxxx','xxxx','...
1
vote
3answers
3k views

How to Modify this $wpdb query to accept an array of post statuses

I'm using this function from this accepted answer, which gets all values for a custom field key (cross-post). How could it be modified to allow an array of post statuses? function get_meta_values( $...
0
votes
2answers
111 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
93 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 ...
1
vote
2answers
790 views

wpdb->insert not working

EDIT: Rewrote the page from scratch and have been unable to figure out the differences. The new page works as expected. Checked multiple questions here and also on Wordpress.org with no luck yet. ...
1
vote
0answers
44 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
41 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
27 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
108 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 ...
6
votes
2answers
2k views

What is the best way to sanitize data?

I've read several topics about this and different people have different views on the best practice. In terms of WordPress, how do I write data to the database the safest way? This is one insert I'm ...
0
votes
1answer
35 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 ...
11
votes
5answers
8k views

Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title

I'm working on a custom taxonomy term page template where we want the items that are connected to the term sorted by a publication date (custom date field) - and if there are multiple items on the ...
0
votes
1answer
15 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
45 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 ( ...
1
vote
2answers
63 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
0answers
24 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 ...
4
votes
2answers
14k views

$wpdb->insert not working in any way

I know this type of question has been asked over and over, but I couldn't find a solution for my problem, so I hope you can help me. I am using WP 3.3. and I have created a custom table. Now I want to ...
0
votes
3answers
5k views

How to delete all records from or empty a custom database table?

I can't seem to find a simple reliable way to do this - perhaps?: // delete row ## global $wpdb; $delete = $wpdb->query( $wpdb->prepare( "DELETE * FROM `wp_table_name`" ) ); ...
0
votes
1answer
60 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
37 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
29 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
23 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" required>&...
1
vote
0answers
33 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 (118,117,116,...
1
vote
0answers
46 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
20 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
46 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 ...
0
votes
2answers
36 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
129 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 Leggings;http://nlyscandinavia.scene7.com/is/image/nlyscandinavia/...
0
votes
1answer
39 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
14 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
54 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( $...
-1
votes
2answers
3k 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
4answers
9k views

Pagination with custom SQL query

I have my own SQL string to select Custom Post Type posts with specific WHERE clause. I've used the offset and limit to return appropriate posts depending on a page being displayed. That's working ...
0
votes
1answer
119 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 $wpdb;...
0
votes
1answer
79 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"> <th><?...
0
votes
0answers
66 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 ...
1
vote
1answer
94 views

Custom Post Type + 20k posts = blank/404 within Admin edit.php [duplicate]

I have registered a custom Post Type via register_post_type(), and about 45 Custom Fields via add_meta_box() function, within the theme. Custom Post Type Args: 'labels' => $labels,...
0
votes
2answers
73 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 ...