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
1
vote
0answers
701 views

WordPress (on AWS ubuntu) database Fails “Connection refused in .. /wp-includes/wp-db.php on line 1531”

I'm trying to troubleshoot the issue I'm having. Every once in a while (seems to be every couple of nights, during overnight) the database fails to connect. Here is the error log: PHP Warning: ...
0
votes
1answer
76 views

Delete comments function

I've done a function that shows to the logged in user all her comments and gives her the possibility to delete them singularly through a delete button related to each comment printed. The function ...
1
vote
1answer
164 views

wpdb print all post meta

I create query to make an output all meta value from meta key select_analyst but if I put OR to include two post_status it's print all postmeta. Could you please tell me what I am doing wrong? If I ...
0
votes
1answer
1k views

How to Update multiple rows using $wpdb->update

I have created dynamic add/remove fields in a frontend post submission page. Using $wpdb->insert, the system is working perfectly. I have also created a draft edit page on the frontend. On this page ...
-1
votes
1answer
210 views

How to delete field using WPDB?

How can I delete a field in my database under the posts table? For example in my posts table where the ID is 800 I would like to delete the a field under the column product_rank. Any help will be ...
0
votes
0answers
136 views

2 $wpdb queries causing error Table 'wp_postmeta' is specified twice, both as a target for 'UPDATE'

I am attempting to run an SQL query on the post meta twice to update 2 values, I get the error: Table 'wp_postmeta' is specified twice, both as a target for 'UPDATE' and as a separate source for data ...
0
votes
1answer
140 views

Need help converting get_user_meta [keys] into own array

I have a plan to dynamically apply css values to elements on a page based on user specific meta data, so colors and page elements adjust based on what an individual user has seen/done before. So I ...
0
votes
1answer
48 views

Exclude Posts Using Meta Query and User Meta

I have a loop that is working great and doing exactly what I want. The problem is that I need to exclude specific posts that have already been marked as viewed using add_user_meta. Each post is marked ...
0
votes
1answer
741 views

Cannot access $wpdb, comes back NULL

I'm developing a rather simple plugin using the Wordpress Plugin Boilerplate. Utilizing AJAX, I set up a action based upon a button press that's supposed to remove an item from the custom database ...
0
votes
0answers
106 views

Debugging db calls: $wpdb->insert works on test site, not on identical production site

I have 2 sites on the same server, one is production, one is test. Test site works fine, production does not. They are pointed to unique databases. I added a new table with 5 fields to each. My $wpdb->...
0
votes
0answers
133 views

Can't save ajax value to database

So I'm making AJAX request and trying to save my quiz score to wordpress database. To start with, I don't even know which table would be the best for my case to save to or should I even consider ...
1
vote
2answers
1k views

Warning Notice $wpdb->prepare incorrect number of arguments passed

I am receiving this notice when trying to use the $wpdb->prepare function: Notice: wpdb::prepare was called incorrectly. The query does not contain the correct number of placeholders (7) for the ...
0
votes
2answers
506 views

wpdb LIKE request shows all database data

I would like to get a list of user_nicenames and the ID. But not all the usernames which is what i'm getting now. I understand I should use the % before and after the $name only nothing seems to be ...
0
votes
2answers
1k views

Valid SQL query return empty

I see the following string when I print my prepared query: "SELECT p.ID, COALESCE(w.value,Display_name) value, p.post_title, p.post_date, p.post_content,p.post_author,user_login FROM wp_posts p INNER ...
0
votes
1answer
241 views

AWS Bitnami Wordpress - SELECT command denied to user

I'm using Amazon Web Services (AWS) Wordpress which uses Bitnami. I've created a test template, wrote a SELECT statement to test pulling data from the database, uploaded the template, selected the ...
1
vote
1answer
324 views

How to display user_nicename and usermeta values by custom query in Wordpress?

I am trying to display user_nicename and one of usermeta values where meta_key is description. My query is given below: <?php $querystr = " SELECT * FROM $wpdb->users, $wpdb-&...
0
votes
0answers
40 views

Update 2 wordpress tables at once

I'm connecting to a WordPress database using the wpdb class to select the data that I need from wp_posts and then insert in to another wp_posts table in another database. So if I make changes on one ...
0
votes
1answer
251 views

Update database record in plugin

I am developing a plugin now i want to update my table record.... I'm using this code to fetch data from database But i need to update data... also i am sending the screenshot of the database.... ...
0
votes
1answer
2k views

How to Fetch values from WP database based on selected option value by onchange using PHP?

I have retrieve data from WP db and display in select list. But I cant able to store the selected option value in php variable. And I cant able to display data based on selected value. The data should ...
0
votes
1answer
367 views

Unable to use $wpdb in Wordpress

I use mySQL database in Wordpress. I'm trying to use simple database query in wordpress. <?php global $wpdb; $problems = $wpdb->get_results( "SELECT * FROM $wpdb->ma_usermeta"); ?> When ...
0
votes
2answers
606 views

mysql query - how to escape apostrophe?

I've got this query: $tenantsInfo = $wpdb->get_results("SELECT * FROM exp_ten WHERE tenant_number = " . (int) $user->ID); I use some echo to show data on frontend: if ($tenantsInfo) { ...
0
votes
1answer
195 views

Wpdb get->results to out the the month from the db

I'm not getting the correct result from my attempt on creating a table with all the different months displayed and then how many the avg weight was for that month. THIS IS WHAT I'VE GOT: Right now i ...
1
vote
2answers
414 views

Replicating the WP_Query 's' param with $wpdb

Take this basic query: $posts = new WP_Query(array( 'post_type' => 'page' 's' => 'some search query' )); WordPress will split the some search query into 3 separate search terms, which ...
1
vote
1answer
591 views

Foreach loop not working as expected - custom tables and references while submitting a form

I have two custom tables and i would like to have a form submission with the name of the redskabs tables to make an reference to my registreringer table. But im confused to how foreach is working in ...
0
votes
1answer
1k views

Custom tables and using wpdb to insert into DB from a html form

Im using custom tables to make a user register page of something they've done. I'm having problems understanding wpdb and how to use it to insert the data from my html form and how to connect those ...
0
votes
1answer
355 views

implementing my wp_query using $wpdb class

I have two custom post type doctors and location. Each doctors post relates to a location post using Advanced Custom Fields relationship field. I want to write my WP_Query() code using $wpdb class and ...
0
votes
1answer
2k views

insert data from a form:: Warning Empty query mysqli::query()

I'm unfortunately getting an empty query warning and i cant seem to find the issue I hope you'll help me. mysqli->query( ) --> $result = $conn->query($sql); is where it tells me i'm doing something ...
0
votes
1answer
106 views

How can I get $wpdb to show MySQL warnings?

In some cases, when given a bad query, will attempt to run the query, and give a warning (instead of an error). In the MySQL prompt, to see these warnings, you can run SHOW WARNINGS;. For instance: ...
0
votes
0answers
68 views

Intermittent problem writing update_user_meta

I have an intermittent bug in my WP/PHP code related to updating a stored integer counter variable using update_user_meta. Basically, the code is triggered from an external HTTP request which among ...
0
votes
0answers
200 views

Correct and secure way to access a custom SQL database in a custom PHP template file

I am currently developing a WordPress site with Wampserver64 (localhost). I have created a custom SQL database using a custom plugin, wp_my_database, located in the wordpress folder. I can access the ...
0
votes
1answer
381 views

Insert user register into my own user table instead of wp own user

I have found this register form on http://www.sutanaryan.com/2011/12/wordpress-custom-registration-without-using-a-plugin/ but in this case it is registering into wordpress own user table. What i ...
0
votes
0answers
676 views

Rewrite SQL query as a prepared statement and use in foreach loop

I have a sql query that I use to populate a table with data. It looks like this <?php $client = $wpdb->get_results("SELECT concat (string, string2), type FROM `file` WHERE `code` = ...
0
votes
0answers
178 views

How to return count of items found in SQL query

I have a table of hikers and hike sign up data, and need to query it to find out if a particular hiker has already signed up or not. Each signup has a unique key that I can query against. I've ...
0
votes
1answer
46 views

About wp database hooks (error establishing connection)

Is there a hook, which is being called immediately after/before Error establishing a database connection? The problem is I want to log some warning if it happens to api logger. If no, is there ...
0
votes
2answers
7k views

How to delete a particular row in a database table

Here I created a custom profile page based on the current logged user to check only his own data inserted in a custom database. You can see that in every row, I added a button "Delete" missing the ...
1
vote
1answer
465 views

wpdb::prepare() isn't working

Here's my code: global $wpdb; $table_name = $wpdb->prefix . 'product_codes'; // Check if codes exist $query = $wpdb->prepare( "SELECT * FROM %s", $table_name ); $existing_data = $wpdb->...
1
vote
2answers
45 views

How WordPress reacts to a lack of memory of the server [closed]

I am a newbie with WordPress and I have a little question. I met an issue this morning ("wpdb class was not found") with WordPress and while debugging I find that my wpbg.php file was empty ! Here ...
1
vote
0answers
397 views

$wpdb->replace: WHERE?

My plan is to upsert values in a custom meta table with $wpdb->replace. This is what I try: $up_meta = $wpdb->replace( 'spieldaten', array( 'spiel_uid' => $uid, '...
0
votes
1answer
492 views

SQL query for custom taxonomy slugs

I need an array of custom taxonomy slugs. In the front-end, I get it using get_terms(): $tax_slugs = get_terms( 'course', array( 'fields' => 'slugs', 'parent' => 0, 'hide_empty' => 0 )); ...
0
votes
1answer
503 views

Modify Database in Multi-Site wp_usermeta table

My name is Antonio and i'm from Ecuador, my english is not good but here we go. I already have my Multi-site installation working, but the "wp_2_" site have some error in the functionality, because i ...
0
votes
1answer
839 views

Select two value from meta key and post meta

I want to ask best method to select two meta value from same column my code global $wpdb, $bp; $user_id = get_current_user_id(); $vlues=$wpdb->get_results(...
0
votes
1answer
220 views

How to use WHERE NOT EXISTS query to avoid duplicate entry using $wpdb to save in custom table?

I am new to worpress database and stuck on checking duplicate entry of user email. I would like to convert the following sql query in $wpdb $sql = "INSERT INTO trip_rate (id, trip, rating, r_name, ...
0
votes
1answer
110 views

In which file to use $wpdb and its functions for database operations and queries in wordpress?

I have created Page template in wordpress called student to insert data in database using wpdb but i got error insted like this-
1
vote
0answers
77 views

wpdb php get_var query to get ID for URL image doesn't work for ID over 999

I have been using the following php code in a custom plugin to successfully capture the image ID for a media image URL in Wordpress global $wpdb; $picture_ID = $wpdb->get_var($wpdb->prepare(...
1
vote
1answer
122 views

Set Condition echo function get_post_meta

I want to try echo marks of the specific quiz by name I have two quiz for each course. Quiz One Quiz Two I call a function to echo marks global $wpdb; $marks = get_post_meta($course_id,$...
0
votes
1answer
1k views

How to get specific table by current user login

I'm using contact form 7 and "save contact form 7". I want that the logged user see only his own fields. So, He'll see results only if $reservation->user is equal to $current_user->user_login. ...
0
votes
3answers
66 views

Counting posts with argument without retrieving the posts

I have a quite extensive database, 30000+ items, and using this: $args = array( 'posts_per_page' => -1, 'post_type' => 'books', 's' => $s ); $post_counts = ...
6
votes
1answer
8k views

Get error messages when $wpdb->insert() returns false?

$wpdb->insert() returns false which I've learned means that the insert failed. Now, I would like to know why it fails with the insert. According to this ticket https://core.trac.wordpress.org/...
1
vote
1answer
275 views

Why doesn't my insert query work?

I'm trying to insert to the table in my wordpress database but for some reason it's failing all the time. $table_name = $wpdb->prefix . "wp_list_press"; $res = $wpdb->replace( $table_name, ...
1
vote
1answer
2k views

How to correctly pass values to wpdb->prepare()?

Look here: // $term_slugs is a function argument: array('foto', 'video') $term_query = "t.slug IN ('" . implode("','",$term_slugs) . "') "; $ids = $wpdb->get_results($wpdb->prepare(" SELECT ...

1
3 4
5
6 7
22