Stack Exchange Network

Stack Exchange network consists of 175 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
0answers
13 views

how to make Wordpress DB lookup code to do “if” funcation

I have a wordpress website that using WPUM to creat accounts and mange them and a coustem plugin for memberships. When users creat an account they chose from membership plugin membership kind ( Sun - ...
0
votes
1answer
16 views

How to get INSERT errors from $wpdb?

I have these $wpdb->suppress_errors(false); $wpdb->show_errors (true); $wpdbp = $wpdb->prepare($preparedQuery->query, $preparedQuery->values); $result = $wpdb->...
2
votes
2answers
154 views

Is there a (better) way to access $wpdb results?

I have this: global $wpdb; $wpdbp = $wpdb->prepare('SELECT EXISTS ([some query] WHERE user_id =%d);',$target_user_id); $result = $wpdb->get_results($wpdbp); I want to know if the ...
0
votes
1answer
30 views

How to get a list of WordPress default database tables?

Is there any solution to get a list of default database tables in WordPress? I have used $wpdb->tables() but even with blog argument, it returns a list that includes other tables too. (I have some ...
1
vote
1answer
37 views

Get .subsubsub count of post per status queried using pre_get_posts

My following query using pre_get_posts shows the Author only certain posts or pages with certain statuses that s/he should only see and of what belongs to him/her. Is there any way I can get a count ...
0
votes
0answers
23 views

Warning wp-db.php on line 1172

From time to time my site has presented these warnings in the log: Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /.. mypath ... /wp-includes/wp-db.php on ...
1
vote
1answer
19 views

Global $wpdb is not showing correct data with function call

I have a code which shows last 3 recent updated pages or post. This code is working perfectly when I add it on theme sidebar.php file. <?php $today = current_time('mysql', 1); $count = 3; if (...
0
votes
1answer
26 views

Search database with WPDB using a php variable

I'm trying to do a basic search feature for my website database. I want to search the text content inside a custom database table using Wordpress and WPDB. For some reason the search is not returning ...
0
votes
0answers
11 views

WPDB Get Array Of Taxonomies With Post Count

I'm trying to get an array of taxonomies with the count of post types using $wbdb. I would like my array to be: [ [term_name] => [post_count_by_term] ] I've started setting up my SQL query, ...
0
votes
0answers
35 views

SELECT max(meta_value) FROM wp_postmeta in current Category

I need to display the maximum price and minimum price of product From the current category I found this topic SELECT max(meta_value) FROM wp_postmeta WHERE meta_key='price'... stops working ...
0
votes
0answers
24 views

How to have differents sites share the same tables of DB?

I want to have multiple versions of my site that share the same database. I'm wondering if this is as simple as just cloning the site and then in the wp-config having them all use the same database? ...
3
votes
1answer
37 views

Get data from database table by post_id to get data from second database table

I have two db tables: wp_comments and wp_ratings. I'm trying to create a query using $wpdb which has to do the following: from wp_comments I have to get the comment_ID's where the comment_post_ID is ...
0
votes
3answers
63 views

Sql query triggered twice

I am trying to collect data from a search box. Conditions; if the value exists, update the counter field based on how many times it's been searched. Problem: when a duplicate value searched in the ...
0
votes
0answers
19 views

Sort custom post type by other custom post type field. (Places by their reviews mean vote)

I'm trying to sort Places (first custom post) by its Reviews (second custom post) average (mean) vote. So, basically I have two custom post types, one is Places and the other one is Reviews. Reviews ...
0
votes
1answer
23 views

Order by custom table and multiplication

I want to order posts by multiplying values from a custom table. +---------+------+------+------+------+------+ | post_id | a | b | c | d | e | +---------+------+------+------+------+--...
0
votes
2answers
25 views

How to work with constraints on wordpress user metadata?

For example, I want to add a custom user metadata field for projects he is assigned to. But this field must have a foreign key constraint to another table to make sure that the project it is ...
0
votes
1answer
25 views

Connecting to a different database

In my site I'd like to pull in data from another table, without having to create an API from the other site. I have seen that you can do something like this: $wpdbtest_otherdb = new wpdb('...
0
votes
1answer
24 views

Getting Error Trying to Create Table

I'm trying to create a new table in phpmyadmin. I'm using MAMP and this is of course inside wordpress. <?php function testtheme_database() { global $wpdb; global $testtheme_db_version; $...
0
votes
2answers
26 views

Where is the HTML-handler part in the wpdb class?

I'm trying to understand how datas are being handled when saving to the database in the wpdb class. I have searched for where HTML string datas are handled and found a method in the $this->query() ...
0
votes
1answer
45 views

wpdb Cannot Update column in Database

In the custom table, I try to update a specific column with using $wpdb->update class and using HTML form for updating one column that has same id (in here dlname Is ID of data ). The problem is this ...
0
votes
1answer
17 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
25 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
20 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
vote
1answer
33 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
24 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
22 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
73 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
42 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
26 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
39 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
50 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
32 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
54 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
22 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
22 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
113 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
79 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
18 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
124 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

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
105 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
18 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
116 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
19 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
98 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
61 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
34 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
29 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 = ...