Questions tagged [wpdb]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
5 views

Set MySQL variables in WPDB

I have an SQL query that works beautifully as a Raw SQL query, however when I put it into WPDB it throws an error: global $wpdb; $sql = "SET @product_group = (SELECT product_group FROM ...
0
votes
0answers
21 views

Creating multiple tables with Plugin

I opened a new question, just to be sure. The former request has partly been resolved. I got another question regarding creating tables for wordpress: Only one table is created (The first one), but ...
1
vote
1answer
37 views

Problem with creating tables for Plugin

I hope someone can help me. I try to execute this code to install the tables for my Plugin. But for some reason it doesn't work (Doesn't appear in my wordpress database) and I can't find out why. Can ...
0
votes
0answers
15 views

any word search Wordpress

By default, WordPress searches by keyword. What this means is that when passed the search query football boots, WordPress builds the following for the WHERE clause: ((wp_posts.post_title LIKE '%...
2
votes
1answer
47 views

how to execute different sql query in non-sanitized $wpdb->get_results function

I saw $wpdb->get_results that function is not sanitized by core code($wpdb is get_results escaped). For example, in following code $wpdb->get_results( "DELETE FROM `wp_postmeta` WHERE `...
0
votes
0answers
8 views

page can't redirect in Faq custom plugin in admin page

I was trying to delete row in admin page for Faq custom plugin which I made. I made custom Faq plugin and connected it through database. Get all data on front-end and in admin page of plugin. I wanted ...
1
vote
1answer
13 views

Constructing a dynamic WPDB query with multiple LIKEs

I need to query the database table using multiple strings. A row should be selected only if the "tags" column matches all the strings. I don't know the amount of strings beforehand (it's ...
0
votes
0answers
22 views

Wordpress update databse table

Can anyone explain to me wpdb update database I would like to understand about $where (an array of field name). $table The table name. $data A PHP array where the keys are the columns and the values ...
1
vote
1answer
22 views

wpdb function for filtering the images by title

I want to write a function using wpdb by which if I click on an alphabet it will show images that starts with that alphabet
0
votes
1answer
25 views

Use $wpdb or other PHP script method to find/replace in WP database

I'm hoping to push a bug fix for a custom WordPress plugin my sites use. The plugin registers a shortcode with various attributes. However, there's a bug where one of the attributes is incorrectly ...
2
votes
1answer
115 views

Should close $wpdb via $wpdb->close()

I’ve been writing a few custom plugins for my site and I was wondering about the correct way to interact with $wpdb. My plugin executes a few queries using the global $wpdb connection. I noticed that ...
0
votes
0answers
12 views

What is the lowest hook deal with database?

I need to track every process done on the database, so what is the lowest hook applied to the database processes?
1
vote
0answers
13 views

How to Instantiate wpdb Object in New File

I have a shared hosting account which does not permit me to connect to my databases via mysqli or PDO. However, I can install WordPress and interact with the database via the various built-in forms. ...
1
vote
0answers
34 views

how to search users by ajax live search

in short i want to search users with with help of live ajax search . i have written a code and it is working fine but that code is for searching posts by ajax, but i want to search users from ...
0
votes
1answer
15 views

SQL queries to another wordpress site

I have 2 wordpress sites on the same hosting and the same host/user/ password for the database I have on the other hand 2 different database and 2 different prefixes I need, during an action on site1, ...
0
votes
0answers
25 views

when using $wpdb sudden connection rejection without changing anything. Access denied, with errors from repair tool

WP version 5.5.3 - updated days ago php version 7.3.24 running locally on server Can not create a backup using duplicator Occours bothi inside WP admin pages, so internal connections and external ...
0
votes
0answers
19 views

Insert NULL value using prepare()

I have similars queries /* Query */ global $wpdb; $tablename = $wpdb->prefix . 'data'; $sql = $wpdb->prepare( " UPDATE $tablename SET `date` = %s, WHERE id= %...
0
votes
0answers
19 views

Remove all \n\t from $wpdb->prepare()

If I have a prepare method with a lot of fields like the one below, to make the code more usable and clear, I always separate the rules of my query with newlines, but if I have problems with these ...
0
votes
1answer
25 views

wpdb COALESCE won't work

I am struggling to get the result using COALESCE from custom table. I need to run a second query if the first results null but wpdb resulting query string itself rather than the result. $query = "...
0
votes
1answer
47 views

How to get a value-only flat array from $wpdb->get_results when selecting a single column, without foreach()?

My query is: $var = $wpdb->get_results("SELECT field FROM {$wpdb->prefix}table", ARRAY_A); var_dump($var); it returns someting like array(2) { [0]=> array(1) { ["field"]=&...
0
votes
1answer
12 views

PHP | left join avg query give me Array()

I'm trying to implement a query within my code that gives me the ability to calculate the average value between the ratings received and the number of ratings per post, and sort posts from the one ...
0
votes
2answers
83 views

get_results query with accent

I'm trying to do an SQL query and I don't understand something. I get a value with $ _POST, this value is equal to 'définition'. I made this request: $sql = "SELECT DISTINCT * FROM". $ wpdb-&...
0
votes
1answer
16 views

Fill New Taxonomies

I will explain my scenary and then my problema.. I have more than 10.000 products on my woocommerce categorized by differents name. IE car parts. I need yo create a new type of taxonomy that I will ...
1
vote
0answers
40 views

How do you build a wpdb query dynamically?

My table has 6 columns, 3 of which I'm interested in: id, name, email. The problem is that my query does care about the name, but doesn't always care about email or id. As of now, the code is this: ...
0
votes
2answers
25 views

What is my error trying to create a new table in the database?

I tried creating the tables in different ways and I always get the same error: "Error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the ...
1
vote
1answer
45 views

Filtering posts from different categories into different section by doing WP_Query only once

I am trying to create a custom homepage with multiple categories section. I know this is possible with WP_Query, but i don't want to make multiple db trips. I want to query posts (say 5 each) from ...
0
votes
0answers
18 views

MYSQL TIMESTAMP when adding DATE_FORMAT then the output is blank, PHP conflict?

Usingthe following shortcode function, I have the code building a table by querying the DB. That all works fine. BUT when I add any type of formatting to the TimeStamp column such as DATE_FORMAT or ...
0
votes
0answers
72 views

Any way to use FETCH_KEY_PAIR with $wpdb?

I'm trying to get key/value pair results from a query like PDO's FETCH_KEY_PAIR from a $wpdb query. The closest I found was the OBJECT_K output from get_results(). But that returns the key, but for ...
0
votes
1answer
52 views

Writing a function for WP Cron to run a SQL command daily

I usually use the events manager in PHP MyAdmin to set up scheduled events but since migrating to WP Engine they do not allow it and I must write a function to use WP Cron instead. What should this ...
0
votes
0answers
12 views

how to list all post that are in the custom taxonomy using $wpdb

global $wpdb; $custom_post_type = 'post'; // define your custom post type slug here // A sql query to return all post titles $results = $wpdb->get_results( $wpdb->prepare( "SELECT ID, ...
0
votes
1answer
35 views

get_post() is not returning correct value

I have a post and i need to update its post_parent. So i have used below code to update the post_parent value. Old post_parent is 844 and using query i have updated the value to 370 using below: ...
0
votes
0answers
23 views

How to filter database data based on select options using jquery

I found this code on a website which works fine for filtering data from two different select box but I have totally five comboboxes. I want to extend this functionality to work for the other three ...
0
votes
1answer
25 views

Access to numerically indexed array in wpdb Class and undefined offset

the following database call $einzel = $wpdb->get_row("SELECT t.id, DATE_FORMAT(t.datum, '%d.%m.%Y'), DATE_FORMAT(t.datum2, '%d.%m.%Y'), t.ueberschrift, t.uhrzeit, t.termintext, t....
0
votes
0answers
25 views

update not working using wpdb

I am fetching the row value in the $specie variable, then in the form i am passing the id in the hidden field, but on updating it shows page not found error? what i am doing wrong?? <?php global $...
0
votes
2answers
58 views

Conditional formatting on data fetched from MYSQL

I'm not an expert in PHP and I'm trying to apply conditional formatting on data fetched from wpdb. To be fair, I'm trying to create shortcode for this. My motto is to fetch values for $previous_marks &...
0
votes
1answer
95 views

get_posts() SQL Injection

I'm working on a custom search page and I usually use wpdb->prepare when crafting custom queries. But this time I went with get_posts to create the below query. But I'm wondering if I have to worry ...
0
votes
0answers
17 views

WooCommerce get specific orders by Customer ID SQL

Trying to get specific orders by the customer ID via a raw SQL query. I'd like to input which order IDs I'd like to retrieve, but only retrieve them if they match a specific customer ID, here's what I ...
0
votes
2answers
22 views

how to assign content to a different author while loading content

I am new to WordPress and am learning the platform on the fly. We are in the process of converting a large non-WordPress site to the WordPress platform. In the process, we have several people updating ...
0
votes
1answer
65 views

Problem migrating to localhost

Hey guys :) I have to following case. I was given a WP site for "fixing". The website is huge in size. It's around 3GB and the DB is around 350MB. Most of the DB size is coming from postmeta ...
0
votes
0answers
43 views

How to store sensitive user data (passwords)

I want to create a plugin addon that allows my sites users to share private login information in a secure manner. So they'll enter these private details in a form on the frontend and I want to be able ...
1
vote
1answer
35 views

Show MySQL errors that occur when I excute $wpdb->insert()

I have the same problem as Nathan ($wpdb->last_error doesn't show the query on error), obviously, the solution to the specific case was to change the type of data to the column that caused the ...
1
vote
2answers
41 views

Wpdb result with pagination

i got this function and its working properly without pagination, but right now i need some pagination on page as a listing is grow up now, how can i do that? function listing_items($args){ global $...
0
votes
0answers
16 views

Create a bulk action to pass user profiles into a CPT

I'm following some questions in stack overflow like this one Until now and after also reading how to change databases I can't achieve it. I want to create a custom post type that displays profile ...
0
votes
1answer
101 views

CREATE TABLE with dbDelta does not create table

I based this code from the codex on the docs. I placed it in my main plugin file but it's not creating the database table. Have I missed something? // Database setup and hooks function ...
0
votes
1answer
17 views

How can I add a new row in a separate database when someone registers via Wordpress?

Apologies if this is question is too general or in the wrong location but I am new to SQL, Wordpress and web hosting. So I am a game developer using Unity C# to create a multiplayer game. I am using ...
1
vote
1answer
15 views

When Wordpress Default table, Echo Success. When Plugin Table, Echo Blank

When I used this code, the result/echo display as I wanted. <?php $user_checks = $wpdb->get_results( " SELECT ID, user_nicename FROM $wpdb->users " ); foreach ( $...
0
votes
1answer
40 views

Save data from a checkbox to a wpdb array

I have several fruit checkboxes but when saving to the wpdb database it only saves the last one that it checks, variable $check receives vardump string (6) "banana" string (5) "apple&...
-1
votes
1answer
28 views

Query Problem in Clustom Plugin

I am trying to do some from a custom plugin in tables of WP-ERP plugin. I am using the following code: global $wpdb; $wpdb->show_errors( true ); $table_name= $wpdb->prefix.'...
0
votes
1answer
44 views

Clear Terms from Taxonomy for Specific Post IDs?

Trying figure out how I can use some SQL/$wpdb->query to delete all the terms from a taxonomy that are related to specific post IDs. The following works beautifully to delete all the terms from a ...
0
votes
0answers
23 views

How to securely controlling data without keeping it in postmeta?

I'm looking for another alternative instead of keeping the data in the post metain the post like plugin I developed for wordpress. I want to save the likes of the posts to a database and then show it ...

1
2 3 4 5
23