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
186 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
27k 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
47 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
84 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
81 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
706 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
33 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
40 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
102 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
31 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 ...
10
votes
5answers
7k 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
39 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
57 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
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 ...
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
45 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
33 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
25 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
31 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
42 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
45 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
35 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
114 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
36 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
48 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
110 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
70 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
62 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
87 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
67 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
72 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 ...
0
votes
1answer
83 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( '...
0
votes
1answer
45 views

Proper Prepare Statement for ALTER TABLE and using AFTER

My code for ALTER TABLE doesn't make use of the prepare() method of $wpdb and so the code needs to be updated properly. There are plenty of examples of query SELECT, etc but couldn't find something ...
4
votes
1answer
72 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 ...
1
vote
1answer
45 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
75 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 ...
6
votes
1answer
47 views

Multisite posts in categories on network

I'm running a multisite with a main site and 3 subsites (the number of subsites will be over 200 at the end). Now on every site I have a category called A, Category called B, and Category called C. On ...
0
votes
1answer
62 views

Custom Query - Based on user input

I'm working on displaying suggestions to an input, assisting the user. I'm using the included jQuery suggest. That's loading - and through ajax I'm using a custom SQL query and can see it's ...
1
vote
1answer
51 views

$wpdb to insert html form information

I'm trying to insert posted variables from a form. When I shorten the amount of variables I'm inserting it will sometime pass the information in my mysql database. Once I continue to add on ...
0
votes
3answers
342 views

MySQL query in Wordpress with AJAX

I have a search form which searches the DB and returns back some data. I have managed to use Wordpress wpdb to connect and use select statement on the table and retrieve data. Everything works fine.....