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

How to get last user with wpdb?

can someone please help me with this query: $ultimousuario = $wpdb->get_var( "SELECT TOP 1 FROM $wpdb->users WHERE user_login = 'usuario*' ORDER BY user_login DESC"); echo "<p&...
0
votes
0answers
16 views

wpdb Insert unknown post data dynamic foreach loop

I have this old function which I would like to use in WordPress. public function database_insert( $table, $data ) { $data_key = "("; $data_value = "("; $i = ...
0
votes
0answers
13 views

wpdb update at most one row

I would like to update a row using wpdb update, but always one row precisely. My concern is that in this case targeting the row will require multiple parameters in the where clause, and should the ...
0
votes
0answers
24 views

Loop function does not work for each DB entry [closed]

Here is a screenshot of my table. The following only work for the first entry in the DB table but not for other entries. Do not work for others like this link. Please advise on the following code. /...
0
votes
1answer
24 views

Catching a new wpdb error

Working on a plugin. I need this plugin to connect to a remote database. I'm attempting this early in the plugin. $mydb = new wpdb('user','password','database','host'); And that works. I am able ...
0
votes
0answers
47 views

How to query more than one meta key and value with SQL

I am trying to add a second condition to my SQL where I select from a specific role and another meta key. It works fine with just the role condition but when I try to add the second one it doesn't ...
0
votes
1answer
62 views

Why does wpdb->update delete other meta?

My existing data in the termmeta table: meta_id term_id meta_key meta_value 27374 546 1C_id 9095b4cf-969d-11e9-a601-5cf3706390c8 27918 546 tax_position 1 My code: $found_id = $wpdb->get_var(&...
0
votes
1answer
36 views

Get data from custom table and update relative post_meta based on meta_key

long story short: I need to retrieve data from WordPress-created custom Table and add/update metadata to the related post (post_type=product). I can match the posts (products) and custom table fields ...
0
votes
0answers
27 views

How do I get database rows from a custom table using wpdb?

I'm trying to get particular rows from custom table into an object using wpdb. From the cli of the mysql client, this line yields the rows I want: select * from wp_94b3c05783_wpforms_entries WHERE ...
1
vote
0answers
26 views

How can I connect to a second database and still be able to use wp functions like get_post_types()?

I have several WordPress sites that I manage where I will need to get post data from one site and display it on another. Ideally I would like to connect to the second site's db and pull the post ...
0
votes
1answer
40 views

SELECT rows between two datetimes when the range is dynamic [closed]

I'm trying to select rows that fall into a certain date range from my database table. The range is determined dynamically by the user. In my database I have a column called "dateAndTime". It ...
0
votes
1answer
13 views

User set date and time from frontend doesn't get stored into database

My application lets users store diary entries into a database table. They are free to set the date and time to what they need using html inputs (so I can't simply use the current time because they ...
1
vote
0answers
31 views

How to fetch WordPress database values in JavaScript widget

I am making a WordPress widget. There are 4 screens of my widget with some input fields and buttons. on first load i display only first screen and hide the others. The idea is to display the second ...
0
votes
1answer
47 views

Wpdb query with dynamic table name

I have a separate custom table in my database for each language I'm providing for my website. I need to select the correct table dynamically from a variable that is sent from a POST request. First I ...
0
votes
1answer
27 views

$wpdb->prepare was called incorrectly when inserting multiple records

This works: $values = array(); foreach ( $_POST as $key => $value ) { $values[] = $wpdb->prepare( "(%d,%s,%s)", $post_id, $key, $value ); } $query = "INSERT INTO {$table} (...
0
votes
2answers
35 views

Increment integer field in database when WHERE needs to be dynamic [closed]

I have a database column called "upvotes". I have another column called "userid". I would like to increment the value in the "updates" column where the userid matches the ...
0
votes
0answers
22 views

no result returns when using $wpdb->get_results with where clause

I have 2 mysql queries, 1 with where clause, 1 without where clause. The one with where clause is not able to generate results eventhough the query is correct, I have tested it on PhpMyadmin. ...
0
votes
1answer
27 views

How to protect a script execution on Wordpress?

Recently I have created a script to update records on my Wordpress database. I basically use wpdb to connect to another database, grap some records, and update the Wordpress database. Using only ...
0
votes
1answer
24 views

CreateOrUpdate in Wordpress

the laravel framework has a handy function that is called updateOrCreate(). How can I do something like this in wordpress, whereas Flight is the model in laravel and could be replaced by $wpdb: $...
0
votes
0answers
35 views

How to get image path from id using SQL

I want to use a SQL query to get some random users and display an advanced custom fields profile image. Currently with this query I get the image ID back but I somehow from that need to get the url ...
0
votes
1answer
21 views

dynamic css file for admin / backend and get_option results in Uncaught Error: Call to undefined function get_option()

I try to style the admin area with a dynamic css. I need to configure some elements regarding the frontend user defines. He can choose a color and this color should reflected in some elements in the ...
0
votes
1answer
11 views

Does WordPress have something like Drupal's DB API?

That is, the ability to write database queries like: $query = db_select('users', 'u'); $query->condition('u.uid', 0, '<>'); $query->execute(); I'm converting a Drupal site to WordPress, ...
0
votes
1answer
13 views

get posts whether meta_key exists or not

I am trying to get custom posts using $wpdb->get_results() as follows: SELECT p.ID, p.post_content, p.post_title, p.post_excerpt, pm1.meta_value as meal_date, (case when pm2.meta_key is null then ...
0
votes
0answers
8 views

XML post import from folder -> Checking title to avoid double import not working

I'm trying to import xml posts from a folder within WP. I'm using the following code: /** * Create and insert posts from XML files in folder */ add_action( 'admin_init', function() { ...
0
votes
0answers
19 views

How to query results for post_title and Custom Post Type/ACF field pivot query

I have a custom query that needs to match a search term to a custom post type of event by post title and by an ACF field host and then filters out events that have passed the current date to a REST ...
1
vote
0answers
18 views

Getting post revision and printing them on the post content site

I trying to print older post revisions on the content.php site (theme: twentytwenty), and this, with staticly set value works.. $query = $wpdb->prepare("SELECT * FROM {$wpdb->prefix}posts ...
0
votes
0answers
70 views

How to insert a value to decimal type field using wpdb->prepare?

I have a table myTable with a decimal(12,2) field named balance. I want to update the table using the following code. $query = $wpdb->prepare("UPDATE myTable SET balance = %d WHERE id = %d&...
0
votes
1answer
41 views

WPDB: Update table

I am currently developing my first WordPress plugin and am currently a bit confused on how to change a record in a database. So far I have solved it using the $wpdb::update() function: public function ...
2
votes
1answer
79 views

How to get all term meta for a taxonomy - getting term_meta for taxonomy

TL;DR: I'm trying to get the meta_value display_type for a taxonomy, but it returns blank (even though I can see it in the database). This question wants to access a term meta that is on a the ...
0
votes
1answer
16 views

Save queried result into database

in multi author website when author publish post , he/her can give star rating to his/her own post. and I can display average rating for every taxonomy term using this formula: AVERAGE RATING=TOTAL ...
0
votes
1answer
33 views

Trying to get variable from WP table and toggle its value

I have a query setup in a function to grab the payment status from a table in wordpress using a search string. It will usually be 'Completed' (returned from paypal IPN). All i'm trying to do is allow ...
0
votes
0answers
19 views

Customising the default wordpress search functionality

I find the current from WordPress too strict as it doesn't allow for some minor spelling mistakes. How can I edit this function? I was checking out pre-get-posts however I don't think that allows me ...
0
votes
0answers
17 views

How to select custom posts thats are tagged with multiple taxonomies using wpdb

I want to select post id's of a custom post types (packages) that are tagged with multiple taxonomies (package_filters ['lights','sound','online']). The best I can do is this but its ugly. $sql = &...
0
votes
1answer
20 views

Custom search Dashboard widget

I have a custom dashboard that searches based on meta value. It works ok except that I now need to restrict the results/search to a specific post type, shop-subscription. This is the query I have, ...
0
votes
1answer
89 views

wpdb->get_row is selecting the variable as a column name

I'm using wpdb to get a row of a table $file = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}vip_files WHERE {$file_hash} = `hashcode`&...
0
votes
0answers
19 views

Does this archive template part look like its making too many calls to the db?

I set up a custom post type & taxonomy and registered it as a plugin. Then i'm referencing it from an archive template like this: <?php /* This loop is used in the Archive [.php] template. */ ...
0
votes
1answer
28 views

$wpdb->delete not working for me

I have a function (see in full below) that syncs data into WP from an external database. It's a list of scheduled items. When the schedule is updated, old data should be deleted. See this snippet: $...
0
votes
0answers
20 views

Replacing date values in TIMESTAMPDIFF() with custom fields from wp_postmeta

Two days ago I opened a thread related to the command 'timestampdiff()' -> Old thread). I think I've described the problem a litte bit too complicated, so I will describe it easier in this new ...
0
votes
0answers
27 views

$wpdb: using timestampdiff with custom fields

friends, sorry for my bad english. I hope, that someone could help me with my problem :-) I'm about to relaunch my website, which serves data of thousands of famous people. In the past i retrieved the ...
1
vote
1answer
38 views

Display custom fields from custom posts in RSS feed

I've been struggling with this for a few days and still can't figure it how. What I am trying to do is to add a custom table field into the RSS feed, so I am using Code Snippets for this matter. Below ...
1
vote
0answers
56 views

What is faster: custom taxonomy or serialized post-meta for db retrieval? (over 60,000 posts)

I have a search plugin that can search serialized metadata as well as categories (for multi-checkbox). Is there any advantage to using serialized post metadata instead of creating a custom taxonomy ...
0
votes
0answers
23 views

Is it possible to change the value in the database if it is less than 5

I have a custom table in my database named my-custom and value 19. Is it possible to return the value 19 when it is less than 5? I know I need to write the wpdb-> update function here, but I have ...
1
vote
2answers
54 views

Syntax for $wpdb->prepare when searching in two columns

I have this working statement for searching a single column in my database: $foods = $wpdb->get_results( $wpdb->prepare( "SELECT id, foodname, namevariations, calories, carbs, fat, protein, ...
0
votes
1answer
64 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
36 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
39 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
17 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
83 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
9 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
38 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 ...

1
2 3 4 5
23