Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [wpdb]

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

0
votes
1answer
13 views

Display category names on edit user profile using $wpdb

On the 'Edit Profile' page I'm trying to loop through all the category names using $wpdb. Here is my code <?php function custom_user_profile_fields($profileuser) { ?> <h1>Select a ...
1
vote
1answer
18 views

Using $wpdb->update but confused on the WHERE in and SET

I'm confused on using the where in the $wpdb->update :/ These last few lines of my code are MEANT to update a table with an IP address when software is activated. If they change IPs it records the ...
0
votes
1answer
16 views

Using $wpdb | checking entered email against existing emails in db

Without ranting too much, here is my snippet: if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address is ...
-1
votes
0answers
18 views

Wordpress $wpdb->get_results returning null

I am trying to get values using the below code but shows null values. I checked the database and it contains all data but not able to retrieve the data. Thanks for the help in advance. <?php ...
1
vote
1answer
22 views

Foreach loop using $wpdb not results from rows

I'm using $wpdb to develop a plugin to check for some row fields to see if they match and echo true or false. My original code was working when it was a separate mysql DB and accessed that way. As its ...
0
votes
0answers
20 views

No result after wpdb->insert

I have implemented my own plugin (PHP file). It contains a form with questions with input type = radio. I want to submit the answers and load them into the database. My action is calling another PHP ...
0
votes
1answer
16 views

How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page

Let's assume that the $wpdb->query() is properly escaped as needed, so there is no must for use of $wpdb->prepare(). However, some new requirements at Envato, not the w.org, requires to go over ...
2
votes
1answer
24 views

WPDB: how to get the value of a field in a custom database table

For my WordPress site, I would like to echo the value of a column in a row (determined by the user's ID) of a table in the database for my site. This table was created by a plugin so it is not ...
0
votes
1answer
36 views

Help posting values to DB on submit using $wpdb->query

I am not new to WordPress but this is the first time I have tried to use the $wpdb. I have set up a form: <form method="post" action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']);?>"...
0
votes
0answers
8 views

Merging results from (new wpdb) from subdomain forum database with search results on main site search

I've looked at quite a few similar posts but no-one seems to be attempting the same thing as me here. The search page is on the main wordpress site mainsite.com/s=the_query. The forum is at mainsite....
0
votes
1answer
21 views

WordPress Database Query works in phpMyAdmin but not in the code

I have a simple SQL query: SELECT * FROM test_table__csv_import_temp_joblist WHERE url ='https://www.example.com' In phpMyAdmin, it works well and returns a result. In WP it returns nothing: $sql ...
0
votes
0answers
23 views

403 Forbidden Wordpress Database Results

I have a website, hosted on Wordpress. I have created a custom table within the WPDB, with ARI Adminer, called 'people'. I have entered some entries for testing. I have created a test page with the ...
0
votes
0answers
29 views

$wpdb select returns empty array

I am trying to query databse to get posts with meta_key equals meta_value but it returns empty array, while if i used get_posts i got required result, what is wrong with my code (I hooked it to footer ...
0
votes
0answers
18 views

Query multiple Post Types that have the same Taxonomies with different Terms

I have a method that works. However, it's not very optimal and limits WP_Query's functionality (recently with pagination). I saw a similar question/issue, but the answer provided is the current ...
0
votes
1answer
28 views

Ajax $wpdb not returning table data

I'm using WordPress 5.0.2 with WooCommerce 3.5.3 and I have two selects dropdown field on the checkoutpage. I want to retrieve the selected region_code value from the billing_region dropdown and then ...
0
votes
1answer
29 views

Is querying wpdb directly and skipping actions provided by WP's core “wp_update_post” a good idea?

I need to query a lot of posts at once. A lot and performance is more than crucial here - things moving slow will net me bad reviews, a lot of them, but cutting a bit through WP's overhead could net ...
0
votes
0answers
18 views

Select by terms across custom table using $wpdb object

Quick background: I've inherited a WP site that someone else coded and I'm adding extra functionality. I have made a plugin that creates a custom table. My method to query that is like so: function ...
0
votes
1answer
18 views

I can't figure out what's wrong with this statement. $wpdb->query update

I'm trying to use the $wpdb-query method, but can't seem to get it to work. I get a 500 error when I try the following: $update_status = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}...
0
votes
0answers
67 views

update value in database on button click, using a dropdown menu

I am getting the users via $wpdb, then I display the values id,name and mg_nobility in a table that has a dropdown menu to select the nobility and a submit button. how can I get the id of the row that ...
0
votes
2answers
39 views

$wpdb->prepare with LIKE and sprintf

Ok, I know similar questions have been asked before but none of the answers I found seem to work. Here's my code: $sql = $wpdb->prepare('SELECT ID FROM ' . $ignore_url_table_name . " where url ...
0
votes
1answer
17 views

I am using wpdb but it not working perfectly.but if I dont use form data its work

<?php if (isset($_POST['submit'])) { global $wpdb; $table_name = $wpdb->prefix . "table_booky"; $wpdb->insert($table_name, array( "Name" => $_POST['name'], "dep" => $_POST['...
0
votes
1answer
71 views

How to set MYSQLI_OPT_INT_AND_FLOAT_NATIVE option

I'm having troubles with the mysqli driver used by wordpress, where it is converting each and every integer value to a string within $wpdb->get_results("SELECT..."). I know that it is possible so ...
0
votes
0answers
25 views

AJAX is not submitting data to database

I have a quiz application which stores user scores to a variable. There is a blueprint object for every user that looks like this: function User (theName, theEmail) { this.name = theName; this....
0
votes
1answer
54 views

Any possible way to make $wpdb->get_results() return anything else than array?

So I'm using $wpdb->get_results() to query my database and then make AJAX call from JS file. The problem is that I need to get the value itself, like a string, instead of array, but as much as I ...
0
votes
0answers
15 views

AJAX request returns back Array0 to console

I'm making an AJAX request in wordpress for the first time and I'm trying to access my custom made table to retrieve single name (string) or multiple names. It all works without the errors, except for ...
-1
votes
1answer
44 views

Can't access data from database using AJAX

I'm trying to make an AJAX call for the first time in wordpress. I followed some tutorial and have came to this point so far. But when I'm trying to console.log the data I get from database inside my ...
0
votes
0answers
17 views

How to grab data from input and store it into custom table in database?

Question asked million times and answered, but still not working for me for the simplest form. My code looks like this right now: <?php if (!empty($_POST)) { global $wpdb; $...
0
votes
0answers
40 views

Adding query parameter filter to REST endpoint by custom database table

I am adding a query parameter to a CPT reviews REST endpoint of an ACF custom field value with the following: http://mywebsite.local/wp-json/wp/v2/reviews/?rv_type=video Now here comes the issue. I ...
0
votes
1answer
39 views

Show error messages to a user when database insert fails

I want to show a generic error message to a user when a database query fails on my site. I'm new to wordpress and I'm not sure how to go about it. I have the following function in my functions.php ...
1
vote
1answer
25 views

WPDB Update using Conditional Arrays

Issue: I need to use the update function as per exact same format as below, the issue is with the conditional statement for id i.e. [ WHERE (id = 1 OR id = 2) AND status = true] $wpdb->update( ...
0
votes
0answers
23 views

Get column count and value

I am having trouble converting this to wordpress compatible code: $result = $conn->query("SELECT * FROM {$table} WHERE id='$playlist_id'"); $num_fields = mysqli_num_fields($result); $headers = ...
0
votes
1answer
3k views

How to call a PHP function with Ajax when the user clicks a button

I'm developing a wordpress site using custom templates/themes, but I'm having trouble. I want to use Ajax to call a function when a user clicks a button. On one page, I have a button like so: <p ...
0
votes
1answer
117 views

wp_insert_post not inserting post

I'm trying to insert a post when a user (aka me) clicks on the button (this button is inside a meta box on the admin dashboard). This doesn't happen and I don't know why. When I put the content of my ...
2
votes
0answers
52 views

$wpdb->get_results() does not fetch results with unicode 'WHERE' clause

I've just a simple query to fetch a students records by his name, written in Bengali. $student_rcrd = $wpdb->get_results("SELECT * FROM student WHERE name='আবুল কালাম আজাদ'"); Although my database ...
0
votes
1answer
62 views

How to use mysql LIKE with wpdb?

as per title I need to use LIKE operator to delete a row on db programmatically with $wpdb. I wanna use $wpdb->delete to remove an occurrency but I don't know how to set the LIKE operator because ...
-1
votes
1answer
27 views

Get all the related data from WordPress DB

I have 2 custom tables inside the DB WordPress is installed in, With one-to-many relation between both tables. Here are the two tables: posts table ...
1
vote
1answer
52 views

Use Wordpress MultiSite (WPMS) with a remote database for each created site

So, I am interested in really figuring out a way to use WPMS with different remote databases for each new sub-site added. What I know. I know that a remote database can be on it's own server to allow ...
1
vote
0answers
16 views

Update results, Before deleting the related category [closed]

There is a DB that contains 2 tables posts and categories, Each category could contain many posts, So I'm using one-to-many relation between the two tables. Using the id of the categories and a ...
1
vote
0answers
25 views

Storing data in wordpress database from ajax call from different website

What I am trying to do is that, I am providing users with embed code for videos...now with these embed codes I am sending a number, once the user watches the video, I am sending that number back to my ...
1
vote
1answer
295 views

What's the proper way to use a custom table? [closed]

I manually added a table to my wordpress database using sql using CREATE TABLE. I want to add functions for adding, modifying, and removing the data from this table just like with wp_update_user(). ...
0
votes
1answer
25 views

Unable to insert data into using custom plugin

I am trying to insert some data in database which will be received from a form but the array of $wpdb is blank. There is no error reported by WordPress still the records are not been inserted. This ...
0
votes
0answers
29 views

Finding the places saved in database ,nearby the given address using wordpress

I have a custom post named stores ,in that each post contains the full details about the specific store, including the geo location. Then i have a search box in front end where the users can search ...
0
votes
1answer
49 views

PHP -> SQL Query with Summing

So I'm trying to display the sum of Paid Transactions for a customer's account: SELECT SUM(`payment_amount`) FROM `wp_gf_entry` WHERE `created_by` = '2' AND `form_id` = '37' AND `payment_status` =...
1
vote
1answer
57 views

Converting MYSQL to WordPress $WPDB

I’m upgrading an archaic Wordpress site from 3.7. It has some SQL query requests that don’t function after 3.9+ where you now have to connect to the DB via $WPDB (https://codex.wordpress.org/...
3
votes
1answer
117 views

Is their any way to Extend WPDB class and Overwrite the Default Query Function

I am trying to get the Query data with backtrace by extending the wpdb class and overwriting the Custom query function. The code is working fine if i Create a Symlink of db.php but is not working ...
1
vote
1answer
33 views

Multiple postmeta with same name for one post in wp_postmeta table

I have a hidden post meta called _payment for my posts. When i was looking into the tables of the wordpress, I noticed that there are tens of this post meta with the same name for the same post! Here ...
0
votes
1answer
80 views

How to access custom Wordpress database tables

I have this sample code that I found online that's supposed to count the number of rows in a table. Of course... It works, but when I created my own table using phpMyAdmin... It no longer works. What ...
1
vote
0answers
22 views

What's the proper way to add users to my site in order to test things?

I'm new to wordpress. I'm have my site just running on localhost and want to test some things out with dummy data/made up users. When I log in to my wordpress database, I see that there is a table ...
1
vote
1answer
78 views

database interactions using OOP

I'm developing wordpress plugin which store data in database. I tried to start OOP way for my plugin according to boilerplate from Best Practicies: https://github.com/DevinVinson/WordPress-Plugin-...
2
votes
0answers
32 views

Get the Plugin Which Triggered a MySql Query in Wordpress?

I am currently working on this plugin, which is similar to Query Monitor in which i Have displayed all the Details present in the $wpdb object. Now i need to find which plugin is Triggering the Query. ...