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
120 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 ...
0
votes
2answers
43 views

$wpdb-prepare : Do I have to bind a parameter to the table name?

I only do a SELECT on a whole table - and the table is defined in a variable: $table = $wpdb->prefix . 'members'; Do I have to bind a parameter to this variable? This caused an error: $result ...
1
vote
2answers
47 views

How to get top 10 user is based on user meta value

I'm trying to get top 10 users in my wordpress blog based on user meta value. I've tried few methods & finally able to get just top one user using below wpdb query. But clueless, how we can get ...
0
votes
1answer
35 views

Using “->” in a page to exceute $wpdb query gives error

I am doing some SQL queries in a WordPress page using the Insert PHP plugin, but the -> object operator changes to -> when I write code in the Text editor, or view in the Visual editor. When ...
0
votes
3answers
511 views

Ajax insert or update data

I've been browsing through similar questions and have yet to get this functionality to work. I'm tracking the progress a user makes an embedded vimeo video and insert data or update data. JS on the ...
0
votes
1answer
130 views

Inserting Post Meta From SQL

I'm trying to get post meta to be updated/replaced with $wpdb and running into issues. I have working SQL, but cannot get it work when coding it up for my WP plugin. Extra note: The post meta being ...
0
votes
1answer
16 views

Depreciated Call -> Function wpdb::escape()

I am getting lots of errors in my debug log: Depreciated Call -> Function wpdb::escape() - Use wpdb::prepare() or esc_sql() instead Instead of just turning off the debug log, I am trying to ...
1
vote
3answers
703 views

Why does $wpdb return strings for mysql integer values?

I find it very inconvenient and hard to understand that the default behavior of the Wordpress db-interface is to convert all integer (and float?) types to strings. e.g $wp_posts = ...
0
votes
1answer
56 views

Why is an empty result an error? ( $wpdb->get_row )

I have a query where I get the highest id from a table. $user_id = $wpdb->get_row("SELECT * FROM $table WHERE id=(SELECT MAX(id) FROM $table)") The table should always have rows, but if for ...
0
votes
0answers
17 views

Private Messages between users

I'm RoR programmer but for sometime I play with WordPress. My problem in RoR wouldn't even exist and here I don't know what to do... I create table wp_wr_messages with all needed fields. I ...
0
votes
1answer
54 views

Accessing external database: ERR_INCOMPLETE_CHUNKED_ENCODING

I installed the "Insert PHP" plugin in my Wordpress page, activated it, and put this code in my page: <p> Connection test </p> [insert_php] $mydb = new ...
0
votes
2answers
66 views

get_row returns empty when data exists

I am trying to run the following query to access my WP cf7dbplugin_submits table but it keeps coming up empty. I have added my table into wp-db.php model as such: Added the contact form table- ...
0
votes
0answers
27 views

Display result from custom post meta query

This is driving me crazy! I'm trying to simply echo the contents of a meta field (twitter) from the wp_postmeta table of a custom post type with the following query outside of the loop : global ...
0
votes
0answers
50 views

Object Cache - Avoid db queries totally

I am using object cache and have cached just about all queries but am stuck with the last 3, on a post archive page. They are all wp core queries. SELECT SQL_CALC_FOUND_ROWS wpm_posts.ID FROM ...
0
votes
1answer
99 views

$wpdb->insert inserting two rows in database

Hi i am trying to insert data in database but $wpdb->insert insert two rows. my code for insert data is global $wpdb; $tablename = $wpdb->prefix . '<TABLE NAME>'; for ($i = 0; $i < ...
0
votes
1answer
32 views

Geographical proximity query using post_meta

I realise this might be an inefficient query, but I'm trying to grab latitude and longitude values from the post_meta table that are connected to posts to figure out the proximity of the posts to a ...
0
votes
1answer
51 views

SELECT query with prepare and placeholder for string

I am trying to learn how to do a simple Select query using $wpdb-prepare. I am checking wether an email submitted by the user is already available in the database. There has to be something wrong ...
0
votes
0answers
32 views

How to access PostgreSQL using WPDB?

I got a separate database using PostgreSQL and I want to access it via the WPDB class. I tried $pgdb = new wpdb('[username]','[password]','[database]','localhost'); var_dump( ...
0
votes
0answers
49 views

Querying custom tables using WP_Query

I am looking to extend the WP database by adding a custom table. I know how to do it using the $wpdb object; however, I have seen on some sites that it is better to use the WP_Query class, but I can't ...
0
votes
0answers
25 views

wpdb->update update the entire table instead of one row

I'm trying to use the update function of wpdb, like this: $wpdb->update( 'protocol_data_list', array( 'used' => 1 ), array( 'cod_protocollo' => $_POST['numero_protocollo'] ), ...
0
votes
1answer
45 views

Custom Post save causes 500 error

Been having issues with getting a 500 error. Sometimes a change is saved, usually not. I've output the $key/$values to verify it's reaching the function and foreach. The output is the first ...
0
votes
1answer
32 views

How can I combine one field using wpdb and group by?

I have the following code in my functions.php where I'm trying to group the quantity sold from woocommerce orders into the variation selected on the product. My query is: $uvuorderposts = ...
0
votes
1answer
257 views

Are term_taxonomy_id and term_id the same? [duplicate]

I have a custom query where I need a JOIN because I want to COUNT all the posts of a specific category. So I checked the tables and I found out that table wp_term_relationships contains a reference ...
0
votes
1answer
23 views

Frontside menu based on custom roles logged in permission

I have two phases to my site, the first is menu, i want my site to hide (normal) menu items if the user isn't logged in e.g when someone visit my site, the menu should be Home About us Products ...
0
votes
0answers
51 views

Inserting PHP code snippet via shortcode

I'm trying to insert a PHP snippet on a WordPress page using XYZ Insert PHP Code Snippet plugin. This is the code that I'm using but it's not working and I can't figure out what's wrong. I've tried ...
2
votes
2answers
96 views

Proper way to work with wpdb to get user's firstname

I want to use $wpdb to get user's firstname. I know how to do it with php and mysql query, but I want to use $wpdb. The problem is that I don't know how to use it. I tried to create simple query to ...
0
votes
0answers
20 views

get_results no result back

I can't get a result back from this query...any suggestion? function per_match(){ global $wpdb; $myrows = $wpdb->get_results( "SELECT id FROM partite;"); foreach ($myrows as $myrow) { ...
0
votes
0answers
30 views

$wpdb global causing issues with plugin class

I am currently building a plugin. I have a main init.php file which loads all the necessary plugin classes. Within one of the classes, I have several methods that call the $wpdb global. One of the ...
4
votes
2answers
644 views

Detecting errors generated by $wpdb->get_results()

How do I detect errors when using $wpdb->get_results()? For example: $result = $wpdb->get_results("SELECT * FROM this is not a valid query"); The preceding code doesn't generate any exceptions ...
0
votes
1answer
32 views

Wpdb empty result only if language is Russian

I'm having a little problem with wpdb query. I need to change content of an HTML select by changing another one ( simple and clean ), so, this is my query: $_queryString="SELECT ...
1
vote
1answer
305 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. ...
0
votes
1answer
32 views

writing inner join in wpdb

I have a problem in writing SQL Inner Join syntax in wordpress, This logic should definitely work, I tried this in phpmyadmin and it works fine SELECT booking_calendars.cal_name FROM ...
0
votes
0answers
78 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 ...
6
votes
1answer
2k views

get_results on large datasets

I am experimenting some very disturbing problem using a custom SQL query. I have a custom MySQL table called trading_datas having 165 lines for 4,4Mo. One field datas of my table is a big serialized ...
0
votes
1answer
64 views

How to get product order by two custom taxonomy in wordpress

Yesterday i stuck in the middle of code that how could i retrieve product belong to specific custom taxonomy ordered by other taxonomy. Table wp_posts: id | post_title ---------------------- ...
0
votes
2answers
89 views

Get number of comments after modifying comment query

I have modified the comment query arguments in comment-template.php from $author_id = get_query_var( 'author_id', 1 ); $comment_args = array( 'order' => 'ASC', ...
0
votes
1answer
39 views

WPDP related functions look to work but they don't

I have a custom database table called wp_wcpl_user_packages which has the following columns: id | user_id | product_id | ..irrelevant columns... | package_limit | package_timestamp | ...
0
votes
1answer
53 views

Generate a unique hash/number for tracking on $wpdb insert

I want to generate a unique hash/number that I can use for status tracking for an contest. I'm going to use this hash/number in a url created with add_query_args. The url creation will look something ...
0
votes
1answer
49 views

Store plugin page content in wp_options?

I want to write a plugin for wordpress that in some cases will show some content as if it were a post or page as an end result of a form processing. My idea is to add a hook that checks for and ...
1
vote
0answers
108 views

Create a table with wordpress plugin boilerplate

I am a new wordpress developer and i would like to create my first wordpress plugin based to wp plugin boilerplate template plugin. My plugin will have to do with my clients data so for this reason i ...
0
votes
0answers
35 views

Using $wpdb_update and foreach loop

I have this function to update data in my table list but it's not working. My insert and delete are working well, but I don't know what's wrong with this: function update_data() { global $wpdb; ...
1
vote
3answers
534 views

Bootstrapping Wordpress MultiSite Outsite of Wordpress - No $wpdb

I'm working on a plugin for a system to use Wordpress as the authentication backend, so that I can use my existing Wordpress users in another application. The plugin works great when running in single ...
0
votes
0answers
130 views

How to execute a SQL-query which contains multiple queries using $wpdb->query?

I want to execute the following Query-String, which contains 2 separate queries using $wpdb->query: CREATE TABLE `foobar` ( `id` int(2) NOT NULL AUTO_INCREMENT, `foo` varchar(22) COLLATE ...
0
votes
1answer
41 views

New User ID not working in custom function with user_register hook

I'm adding data to a table whenever a new user registers on the site. add_action( 'user_register', 'auto_follow_admin', 10, 1 ); function auto_follow_admin() { global $wpdb; ...
1
vote
1answer
45 views

How would I format a query that depends on post parent taxonomy

I'm trying to do a custom query which is outside the scope of a single WP_Query, I think I should be using $wpdb but my SQL is a bit ropey. Also I only need the post IDs returned not post objects. ...
0
votes
0answers
27 views

Querying same column twice with wpdb (for postmeta values, specifically latitude and longitude)

I've seen similar questions around, but I just can't apply them to my case, I'm quite new at this, apologies. I'm trying to create a google map of my posts, using a latitude and longitude that are ...
7
votes
3answers
55k views

$wpdb->get_row() only returns a single row?

Why is it? I tried the same query in the console and it returned multiple rows. Here's the query: $this->wpdb->get_row("SELECT * FROM ".$this->wpdb->users." WHERE status = 'active'", ...
0
votes
0answers
126 views

$wpdb not working in file of WordPress plugin

I am working in WordPress plugin. I create a custom form where user add values and then click on submit button. When user click on submit button its redirect to custom process file, where i write ...
0
votes
1answer
61 views

Run an update query in a function

I need to run the below in a function, it updates my database if certain conditions are met. I can't get it to work and I can only assume its because of the "SET @newnum" at the beginning. I've ...
0
votes
1answer
66 views

MySQL Select within WP Page template

I have one WP page which contains a form that posts data to a table in the Wordpress database called "members", data such as first name, surname, email, role and bio. Table posts fine and data is ...