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
14 views

What's the best way to query from custom table?

I installed a standard theme. Now I have to create a static site with custom queries. Customer should enter own age and family status etc., the following query results in showing insurance rates in a ...
0
votes
0answers
11 views

my function works if call it but not as activation register hook

hi there I have a function which makes some row in a table, If i call it it works normally, but if I use as register_activation_hook(__FILE__,'add_sellers_brand_size_to_db'); it doesn't work, code is ...
0
votes
0answers
12 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
28 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
0answers
12 views

how to create public file in wp plugin to access it from other apps?

I want to write a plugin so that I can connect to it with an app bot, and store information inside the database. Note that because I directly connect to php file inside this plugin, the public ...
0
votes
1answer
15 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['...
-1
votes
1answer
30 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
41 views

$wpdb->insert with wordpress shortcode

I hope someone could help me! I need help about Wordpress shortcode with $wpdb->insert. It works, but it run TWICE... function f_registrazione() { $output = ''; if(!$_POST['txtNome']) { ...
0
votes
0answers
19 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
31 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
13 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
24 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
14 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
13 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
0answers
27 views

Building a logged-in user form that interacts with database

I am building a data-entry form for a wordpress website, strictly for logged-in users with editing capabilities. Conceptually, the user selects a database table from a list. The website generates a ...
0
votes
1answer
28 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 ...
0
votes
0answers
18 views

Securing php templates which access to external DB

I was asked to generate a form as a theme template which must access an external DB only for logged users. It can even write into it. What I did to secure the form is: making the page, which relies ...
1
vote
1answer
23 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
21 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
892 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
45 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
32 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
0answers
30 views

Can't retrieve Terms of custom post type from different database

I have 2 websites : 1 parent website with a job board (custom post type and taxonomies) and 1 child website. I want to display job posts from parent website on child website. So far it's working, I ...
0
votes
1answer
49 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
23 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
49 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
15 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
23 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
261 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
18 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
28 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
30 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
48 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
87 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
27 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
46 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
58 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
31 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. ...
1
vote
2answers
44 views

How to delete taxonomy term when a wordpress user is removed?

i need to Delete wp_terms -> name field when a user is delete . my requirement is admin needs to assign posts to specific users, that is admin need to add a post to user1 ,but user2 should not see ...
1
vote
1answer
673 views

Saving custom form data into database

I am a newbie to WordPress. I've created a custom form in WordPress and I need to know where to put the WPDB PHP code to save my form data. I tried putting it directly in my page but that didn't ...
0
votes
2answers
47 views

How to insert wp_users ->user login name to wp_terms when a new user registering?

i need to insert wp_users -> user_login field to wp_terms name and slugs field,when a new user registering. my requirement is admin needs to assign posts to specific users, that is admin need to ...
1
vote
1answer
27 views

creating custom function to log actions in plugin

This is my first go at WordPress plugin development and any help you folks can give me would be appreciated. This plugin needs to keep careful track of how users interact with certain areas of it. I ...
1
vote
1answer
25 views

How to Mail User after inserting Username in database in WordPress

I have following piece of code, which inserts usernames and other details of users in the database. After inserting the usernames I want to email them using wp_mail();. I am unable to do so. How to do....
0
votes
1answer
68 views

WP-PostRatings: list current user's rated posts

I've found this code to get a list of the current user's rated post, but is not working. plugin WP-PostRatings 1.85 / WP 4.9.7 Any idea? <?php global $wpdb, $current_user; $userranking = $wpdb-&...
1
vote
0answers
33 views

wpdb->term_taxonomy count posts from both published and private posts?

I'm trying to understand why this query won't include both private and published posts when counting and sorting the taxonomy terms. $taxonomyTypes = "AND ( tax.taxonomy = '" . ...
0
votes
1answer
39 views

How to add download link from database on custom page template?

I used a variable in head tag $download = $wpdb->get_results("SELECT realname FROM odm_data where id='$id'"); When I call it using <a href="download.php?file=<?php $download ?>">...
0
votes
0answers
26 views

query database for all past orders

What would be the $wpdb command to check if a value already exists in an order? I have a custom field, but I am wondering how I can query the order database history if a duplicate exists. I just need ...
0
votes
3answers
31 views

How to display only first value of database column in WordPress

I have following foreach loop code... <?php $usernames = $wpdb->get_results( "SELECT user_name FROM wpxa_project_members WHERE project_id = 698" ); foreach ( $usernames as $username ) { ...
0
votes
0answers
50 views

wp_term_taxonomy count column is not saving to the requirement

As I'm trying to insert SubCategory into wp_term_taxonomy table. After executing the below lines of code $query_term_taxonomy = $wpdb->insert('wp_term_taxonomy', array( 'term_id' =>...