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
16 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 ...
1
vote
0answers
21 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 ...
0
votes
0answers
20 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
1answer
3k 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
0answers
10 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 ...
0
votes
2answers
1k views

How to use ajax in wordpress plugin to get data from coustom DB?

i have created php script that work great as stand alone. now i need to create this script as wordpress plugin. so i have created custom table in wordpress DB. then i tried to make the ajax call. in ...
0
votes
2answers
34 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
1answer
655 views

How to insert image path in database to display product image in wp-admin?

In which database table and column do I need to insert an image path, in order to display product images in wp-admin (not on the front end)? I insert products by query in WordPress, rather than insert ...
0
votes
1answer
18 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, ...
1
vote
2answers
545 views

Exclude subscriber users from user list

I want to exclude Subscribers from a user list. My code is: $users = $wpdb->get_results( "SELECT display_name FROM $wpdb->users ORDER BY display_name ASC" ); How can I change that so ...
-2
votes
0answers
17 views

Fetching trash iteam while export

Hello All i have customized visual form builder plugin as per my requirement, I developer custom option like admin user can export the entries as pdf export of the submitted form (As default it has ...
0
votes
1answer
452 views

Delete query won't run

This is the set up: <form method="post" action=""> <input type="hidden" name="delete_app_id" id="delete_app_id" value='<?php echo $adoptee->app_id; ?>' /> ...
0
votes
2answers
22 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
21 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 ...
3
votes
1answer
487 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
1answer
2k views

Action hook “wp_insert_post” works but not for last imported post

I want to run a custom function whenever posts are imported to my custom post type. I am currently running this code - function on_post_import($post){ global $wpdb; $results = ...
0
votes
1answer
20 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
7 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
17 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
2k 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
1answer
463 views

$wpdb->get_results returns empty but value exists

this is my first question here. More then 5 years working with Wordpress, I always find the right way through the Google, but in this case I did not even know what to do, I really stacked :( So ... ...
4
votes
4answers
8k 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
37 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
27 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
27 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
42 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' => ...
0
votes
2answers
30 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
34 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
32 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
19 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
40 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
24 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
33 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 ...
4
votes
1answer
23 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
27 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 ...
0
votes
2answers
4k 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`" ) ); ...
1
vote
1answer
24 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
59 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 ...
0
votes
0answers
12 views

Unique user tables between three sites with same database

I have three websites that have their own prefixes, but are in the same database and have each member, and I have create a system that would allow to confine all its members in a mime table, so to ...
1
vote
1answer
16 views

External DB Connection [closed]

I'm trying to connect and select some data from an external DB. The DB is in the same server as WP, so it has the same username and password, but different DB name. Here's what I'm using to connect to ...
3
votes
1answer
38 views

Converting mysql to $wpdb

I'm trying to convert this to using a $wpdb class. It will return all the enums possible and i have to use this $wpdb due to mysql_query giving me weird error (no database selected) Code is following ...
1
vote
3answers
4k views

mysql query two database tables, users and usermeta and sort by custom meta int value

I am trying to get an array of site users sorted by a custom meta value (an int). I can query the users just fine and get them back to use in a foreach. I currently have the query results come back ...
1
vote
1answer
25 views

Database: Custom table: sprintf value for DateTime column

I am creating an insert query following the insert example on the wpdb class reference. What sprintf like placeholder should be used for a DateTime column on a custom table? Allowed placeholders seem ...
1
vote
0answers
49 views

Proper usage of $wpdb->update()?

I am trying to update my custom table in Wordpress using the following php code but still no success: $tablename = "wpfeedback"; $data = array( 'mark' => $mark, 'comment' => ...
0
votes
1answer
39 views

How to insert dash (-) into database using wpdb and new_to_publish hook?

I am saving titles of posts in a separate table for a specific use. The titles are saved to the database when a post is published. code is: add_action('future_to_publish', ...
0
votes
2answers
42 views

Custom query: Get all posts that are from a certain category?

This is what I have: global $wpdb, $month; $months = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND DATE_FORMAT( ...
1
vote
1answer
22 views

How to prevent $wpdb->prepare stripping a leading zero in variable value?

I have a simple database_read function and per accident I noticed order_id's starting with a leading zero would not give me the expected results. It turns out using $wpdb->prepare strips out ...
1
vote
2answers
5k views

$wpdb->insert - inserting multiple rows

How do I use $wpdb->insert to insert multiple rows. Here is my code. for($i=0; $i<=$urlCount; $i++) { $stat = $wpdb->insert( 'WP_URLS', array( 'POSTID' => ...
15
votes
3answers
12k views

Should I use wpdb prepare?

I'm new to SQL and am wondering if I need to use wpdb->prepare for the following query to a table I've created global $wpdb; $tablename = $wpdb->prefix . "my_custom_table"; $sql = "SELECT * ...
1
vote
3answers
119 views

How to Download and install plugin database remotely

I have the following problem. I got a plugin that is huge due to all the data needed. The data is all the countries and cities in the world and also a maxmind.mmdb database. 1 - Issue Currently I ...