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
1answer
23 views

Delete oldest wordpress post (SQL query)

I've reached the database limit on my hosting platform. I want to add a function to my functions.php that deletes the oldest post in my database anytime that I publish a new post. function ...
0
votes
1answer
33 views

Check if Value Exists in Database, adding row details to variables and echoing result

I am trying to create a UK Postcode checker for a clients Woocommerce shop. I have created a table in Wordpress with the cells, Postcode, Town and County. When a user enters their postcode into a ...
0
votes
1answer
29 views

Strange string in console from wpdb query

I use this code: $search = $this->wpdb->prepare("WHERE (name LIKE %s OR tag LIKE %s)", '%'. $this->wpdb->esc_like($word) .'%', '%'. $this->wpdb->esc_like($word) .'%'); and in ...
0
votes
1answer
23 views

get_results not returning anything

What is the basic way to use $wpdb and get_results? This is my code: global $wpdb; $q="SELECT * FROM wp_usermeta WHERE meta_key = 'nickname' AND user_id = 771"; $result = $wpdb->get_results($q); ...
0
votes
1answer
26 views

show badge with count for pending items in custom post type

This code I have is working but I am not sure if it is the right way to do this. Basically when a user adds a record to a custom post type it goes straight to pending and needs an admin to publish it. ...
0
votes
0answers
11 views

SQL Query - custom tax_query not working when querying two taxonomies

I have a created a custom table in my WP database called wp_opportunities which stores locations with their lat and long. I'm trying to query the table based on the taxonomy term set on the post ID ...
0
votes
1answer
10 views

How to search usermeta table

What is the best way to search usermeta to find a user_id based on a meta_value? For example in usermeta table there is a row with user_id = 123 , meta_key = deviceid and meta_value = 45545. I know ...
0
votes
2answers
16 views

og:image functions.php

I have custom template and i need get og:image url in header. Class image location in DB wp_postmeta - meta_value i try with functions.php function getOgImage() { global $wpdb; $ogimage = $...
0
votes
1answer
13 views

Doing $wpdb->get_results returns NULL, doing the same query in my DB returns correct value

I have this query to do in my code: function get_item($id){ global $wpdb; $post_id_query = "SELECT * FROM wp_postmeta WHERE post_id = ". $id ." AND meta_key LIKE '%main%'"; $...
0
votes
1answer
24 views

wpdb replace returning 1 where delete and insert is expected

If I enter a row with wpdb->replace using an ID that already exists, it's replaced and 2 is returned. If I enter a new row, the ID is auto generated, a new row is inserted and 1 is returned. Perfect. ...
0
votes
1answer
25 views

Remove escape characters from JSON string pulled from a database

I'm pulling rows that contain JSON content from a DB like this: <?php //get the data from the database global $wpdb; $current_user = wp_get_current_user(); $username = $...
0
votes
0answers
20 views

Escape special characters in string

I am using mysql. I would like to insert a string in to a table which possibly contains some characters which would cause query to fail (characters like single quote ' then pipe | maybe some others..) ...
1
vote
0answers
13 views

Querying wpdb using PHP

I'm a beginner trying to query a table in my wordpress database and would appreciate some pointers on where I'm going wrong... I've got a table of cricket statistics, and want to get the highest score ...
1
vote
1answer
44 views

Use WP_Query with a custom SQL query

To fetch the posts I have a query which includes several joins and is quite complicated to use through WP_Query. SELECT p.post_name, t.name as sname, t2.name as cname FROM wpw0_posts AS p INNER ...
-1
votes
1answer
29 views

Is it safe to increase/alter the size of the wp_post.guid column from VARCHAR(255) to VARCHAR(2048)?

I am planning to use External Media Without Import plugin which, like any existing media, uses the guid column of the post table to store the URL of the media (ex: jpg etc). My DB has this column ...
1
vote
0answers
15 views

Would this WPDB setup result in potential race conditions?

I have a page on my site with numerous elements that can be liked/disliked through a simple admin-ajax call. In the associated PHP code, it looks like this: // Fetch the existing meta from this ...
2
votes
1answer
21 views

“The plugin generated 2694 characters of unexpected output…” on Plugin activation, CREATE TABLE sql command not working

Trying to create a table in the wpdb when activating the plugin I am working on and getting the error "The plugin generated 2694 characters of unexpected output…" I've been over the code and done ...
0
votes
0answers
47 views

Custom Plugin Database relations

I will make custom page for my plugin.As a example, in this video, global $wpdb is used to call variables of sing-up form.How can I call my own plugin's variables? I dont know database info yet.Also ...
0
votes
0answers
35 views

wpdb prepare/update not working when the value is the same as current value

I'm trying to update some value in my DB with wpdb and prepare update query. The query is working when the value is different but if the value is the same as the current value in DB the query not ...
1
vote
1answer
47 views

Adding custom end points, No error line

I have been trying to implement a custom end point that inserts data from my mobile application into this database. However, I cant seem to find the correct way to do it. Some places used #wpdp->...
0
votes
0answers
16 views

Updated multiple lines in $wpdb

I have the following code and I'm trying to update all the changes at once. But it did not work. Someone please help me! Thanks! <?php if(isset($_POST['updateDays'])){ $clock = $_POST['...
0
votes
1answer
19 views

Get decimal from product price with Mysql

I try to get min product price like this: $pts = $wpdb->get_results("SELECT post_title, ID, MIN( CAST(wm.meta_value AS UNSIGNED)) AS price FROM phiz_posts INNER JOIN phiz_postmeta wm ON (...
0
votes
0answers
20 views

Limit total number of post and post per page with get_results

I'm using a custom table with a additional column, so I can't use regular wp_query. My code is working great except for the total number of post. I want to display 5 results per page (which works ...
0
votes
1answer
30 views

What is the correct way to search 3 custom fields only in WordPress?

I have three custom fields (not using ACF). I want the search form to search for a match in: _cth_featured_zip_code_1 _cth_featured_zip_code_2 _cth_featured_zip_code_3 This is the query I've ...
0
votes
0answers
18 views

wpdb discards duplicate column names?

using $wpdb->get_results I am joining two tables that have some columns in common, now normally I would expect to get table_a.one and table_b.one both returned, but instead I get only one returned ...
0
votes
1answer
25 views

“This message was added in version X” showing a later version than current one

An error message is displayed : The query does not contain the correct number of placeholders (1) for the number of arguments passed (2). This message was added in version 4.8.3. Problem: I ...
0
votes
1answer
35 views

$wpdb->insert not working for last select option

After reading the posts with similar problems with $wpdb->insert I can't find the proper solution for my problem. I have a template page where I send (via POST) the data to another template page ...
1
vote
0answers
16 views

Populate shortcodes with table data and get next row

Let's say I have a database table wp_myplugin_cars that looks like this: id name color make -- ---- ----- ---- 1 Peter Red Ford 2 Jo Blue Nissan 3 Brian Silver ...
0
votes
0answers
16 views

Query distinct years in a category

I'm building out a custom archive widget that displays a select dropdown of months for each year. How can I extend this query to to pass $categories[0]->term_id? This is my query so far... $...
0
votes
1answer
25 views

Using wpdb to connect to a different database is not working

I am attempting to use wordpress built in database functionality to connect to a different database on local host. I am doing this in functions.php. I have no problem achieving this with mysqli, the ...
1
vote
1answer
30 views

How to update a row in a table in Wordpress

I have a table of data rows. Now I want to click on the Update button then that row of data will be Updated based on the ID Here is my demo: These are my commands: <?php foreach ($...
0
votes
1answer
21 views

How to get specific attribute from DB

a:3:{ i:0;a:2:{s:21:"wwsd_percent_discount";s:2:"10";s:25:"wwsd_minimum_discount_qrt";s:2:"20";} i:1;a:2:{s:21:"wwsd_percent_discount";s:2:"20";s:25:"wwsd_minimum_discount_qrt";s:2:"50";} i:2;a:...
0
votes
0answers
33 views

How to add virtual column in wpdb get_result statement

i want to add a virtual column to wpdb get_results statementthis is my code and the column gid returns nothing . $result = $wpdb->get_results ( " SELECT helo AS gid, calendar_id, day FROM table1" )...
0
votes
1answer
12 views

Using id to show item

Im working on a project where i upload a gpx file and use the path of gpx to put in a shortcode plugin i use the post id the get a filled in shortcode i use this code to get me the piece of info for ...
0
votes
1answer
22 views

Custom array from a query only write the last row of the query

Looking for some input on this one. I am writing a custom array but having a strange issue. It seems to be cycling through the loop and dropping previous values and only storing the last row of the ...
0
votes
1answer
29 views

WordPress Query doesn't return the correct value

According to this page: Return #Return (int|bool) Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error. ...
0
votes
0answers
26 views

How to write the backend for a simple single page application

I want to write a small app on a particular wordpress page which should have following basic functions: After choosing an item in a drop-down menu, get respective information via a GET request (AJAX?)...
1
vote
0answers
43 views

Change commission_status paid when withdraw_status vendor is completed

I need to change commission_status paid automatically after changing commission_status paid when the withdraw_status vendor equals "completed," not check mark. action:$actions = '<a class="...
1
vote
0answers
27 views

Intermittent database errors when accessing WordPress database

Update: I've narrowed this down to a couple of issues that seem unrelated. The testing suite was disconnecting my database without reconnecting. (resolved) The mysqli_free_result(): Couldn't fetch ...
0
votes
0answers
32 views

update_post_meta not working in template_redirect action

I have a problem I'm trying to listen to a webhook, and I can do it, I check with the help wp_mail function and I get all the data But I want to make a add data in the database, and for some reason ...
0
votes
0answers
30 views

$wpdb->get_results returns different results compared to phpmyadmin

this is my sql statement, which works in phpmyadmin: SELECT wp_ccs_cashflowaccounttype.cashflowaccounttypeid, wp_ccs_cashflowbookingtexttype.cashflowbookingtexttypeid, w.invoiceid, ...
0
votes
1answer
22 views

Basic wpdb update question

I can't get this to work and I don't really know how to debug it. In the URL I'm getting this added: ?candidat=41&selectCandidate=selectCandidate global $wpdb; if(isset($_POST['...
-1
votes
1answer
45 views

how to use transient method?

It was suggested to use a transient method to remove the duplicate queries Duplicate Queries Why does this don't work? Is it the wrong way to use it private function get_acf_list() { if(!...
0
votes
1answer
19 views

Custom Query returns array, but I can't see it's elements

guys! I have the following problem to solve - I am using Private Content plugin which divides users into categories. I need to show all posts from the category that the author is part of. I tried ...
0
votes
0answers
13 views

Creating a table from another's results using WP $wpdb functions

Below is the query and function I use to create a table from another table's results: $mytable = "myCustomTable"; $thisSQL = "SELECT p.ID, p.post_title, p.post_author, p.post_status, COALESCE( ( ...
0
votes
1answer
54 views

Get records from Formidable Table using $wpdb->get_col

I am using Formidable Pro as a CRM and one form has a field called cust_id. Now I want to get all the records stored within that form with a specific cust_id. I did: $form_id = 7; $search_id = 300; ...
0
votes
1answer
132 views

Querying specific table row by current user login

I m creating a user based website in Wordpress, where each users can create an account and upload data of their records into the website. But I m having trouble thinking of how users can view a ...
0
votes
0answers
36 views

$wpdb->insert duplicating rows

I'm using $wpdb->insert to insert data into a custom table on my wordpress database. Unfortunately, it is inserting the data multiple times. I have searched through other topics posted, and haven't ...
0
votes
1answer
79 views

Wordpress “wpdb->update” - Append Text Value

I am trying to update a table column by appending some text to the existing value in the column. Basically, I am trying to do something like this: $wpdb->update('table_name', ...
0
votes
1answer
41 views

Prepare WPDB with meta key and meta value

I'm trying to prepare WPDB by post type, meta key, and meta value global $post; global $wpdb; $rid = absint($_POST["rid"]); // number $last_id = absint($_POST["lastID"]); // post ID $query = $wpdb-&...

1
2 3 4 5
22