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
votes
1answer
15 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
577 views

How to CRUD from wordpress database in wordpress theme?

I am in project where I am required to read certain data from a table (which table is created by my plugin, related to this project, I mean custom table, not the default tables of wp). I use $wpdb ...
0
votes
1answer
35 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
2answers
132 views

How to insert wp_users ->user login name to wp_terms when a new user registering?

i need to insert wp_users -> user_login field to wp_terms name and slugs field,when a new user registering. my requirement is admin needs to assign posts to specific users, that is admin need to ...
0
votes
2answers
590 views

Retriving array size from serialized data

I've a custom field in Wordpress user meta, which store data in serialized array. I want to retrieve the number of arrays. For e.g.: a:2:{blah blah} Screenshot of my table I tried the following code ...
0
votes
0answers
22 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 ...
0
votes
1answer
14 views

Limit left join

I am trying to delete posts of post type using left join but i get the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the ...
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
vote
0answers
20 views

Iterating through $wpdb query without using get_results for large query results

Traditionally, whenever I've needed a real mysqli_fetch for things like importing thousands of rows of data, I've used my own database connection and framework. But I was thinking there must be a way ...
0
votes
1answer
630 views

Problem on wpdb queries, wp_insert_post, wp_insert_user etc. The query runs twice

Anyone encountered this issue? I have created a custom php script which adds a new post by using wp_insert_post() but everytime I run the code it creates a 2 new post where in it should be only be ...
0
votes
1answer
20 views

Help with $wpdb on custom code

So i'm trying to implement some custom doing a SELECT to a table i created. I'm using the following: global $wpdb; $fivesdrafts = $wpdb->get_results("SELECT * FROM wpjk_vuln WHERE IDuser = &...
1
vote
1answer
9 views

Redirecting to old domain after migration website

Could someone help me with restoring my website (with new domain name)? I have a database backup and when restore it, wordpress is redirecting me to old website and domain. I changed site url in mysql ...
0
votes
1answer
34 views

Want to filter only parent post in admin area

I want a filter like this in my custom post "books". This filter should only bring up the parent post.
0
votes
1answer
29 views

Check if row exists before inserting

Not sure what I am doing wrong here but I am looking to add a row into db but only if row doesnt already exit with that email address Please see my code below: function register_user() { global $wpdb;...
0
votes
1answer
18 views

Filter in Custom post type to find the parent post

function fws_admin_posts_filter( $query ) { global $pagenow; if ( is_admin() && $pagenow == 'edit.php' && !empty($_GET['my_parent_pages'])) { $query->query_vars['post_parent'] = ...
-1
votes
1answer
1k views

PHP Warning: Error while sending QUERY packet

I have woocommerce website which give database error from 4-5 days. I checked the error log, the error is: PHP Warning: Error while sending QUERY packet. PID=31071 in /home/goldenwiggles/...
0
votes
1answer
14 views

Get posts from category with custom query

I've got a custom sql query to get latest posts from specific category (ID = 62). It looks like this: SELECT p.ID, u.display_name AS author, post_date_gmt, post_title, p....
0
votes
1answer
15 views

How to get inserted row IDs for bulk/batch insert with wpdb query?

I'm writing a plugin where I need to save data in custom tables, function hits an API and then saves data for which I need bulk insert, but as wpdb doesn't support it out of the box I made a function ...
0
votes
1answer
556 views

$wpdb->prepare is not working like mysql_real_escape_string

I'm working on a WordPress plugin and recently I have planned to migrate from SQL to $wpdb. I'm using a method called $wpdb->prepare instead of mysql_real_escape_string but it does not work. Here ...
0
votes
1answer
15 views

Why Query is returning empty array?

I am trying to execute a query using the below code but I'm getting empty array in var_dump. global $wpdb; global $post; $slug = $post->post_name; $course = $wpdb->get_results( "SELECT * FROM ...
0
votes
1answer
22 views

“BS_” rows in postmeta table

I am pruning my WordPress site's MySQL database and noticed that there are thousands of rows in the postmeta table with the prefix "BS_". BS_author_type BS_guest_author_name BS_guest_author_url ...
0
votes
1answer
54 views

Update a row in a wordpress table

I currently have a plugin that displays my table fields in a table. I have made the table into a form, put the table cells as inputs, with the 'value'set to the current column value. I have also ...
0
votes
2answers
959 views

Save custom post type to external database

I'm creating an advertising portal for a small network using a custom post type. In order to prevent WordPress database corruption or unauthorized access to user information, I need to keep data ...
1
vote
2answers
743 views

Problem in inserting row to custom database table

I have a custom table in database named wp_tasks which has 5 fields. But I am unable to insert the current time to assign_date field. wp_tasks table id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, ...
0
votes
0answers
13 views

sort title descending with title with number

please help me, i have title like this '1-nen A-gumi no Monster Chapter 2' '1-nen A-gumi no Monster Chapter 10' '1-nen A-gumi no Monster Chapter 2' '1-nen A-gumi no Monster Chapter 1' '1-nen A-gumi no ...
1
vote
2answers
1k views

$wpdb->insert is running multiple times on page load, but only called once

I created a php class on a separate file I included the file in functions.php I initialized the class The class among many other things has one functions that does this: $data = array( 'time' =&...
0
votes
1answer
28 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
768 views

How to set up prepared query using IN statement

I am a tad bit confused on how I would set up a SQL IN statement using a prepared query. Here is the code: $in = implode(',', array_fill(0, count($product_ids), '%d')); $results = $this->...
0
votes
1answer
34 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
25 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
30 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
1answer
11 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
0answers
13 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
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 = $...
3
votes
3answers
10k views

WP DB Error max_user_connections

I'm currently getting this error in the front-end only (not inside /wp-admin): Warning: mysqli_real_connect(): (HY000/1203): User xxx already has more than 'max_user_connections' active connections ...
2
votes
3answers
2k views

Exclude subscriber users from user list

I want to exclude Subscribers from a user list. My code is: $users = $wpdb->get_results( "SELECT display_name FROM $wpdb->users ORDER BY display_name ASC" ); How can I change that so ...
10
votes
1answer
11k views

wpdb update add current timestamp not working

So using the $wpdb->update to add some data to a custom table, trying to add the current timestamp but it's not saving the right stuff(0000-00-00 00:00:00 this is saved). overview code $wpdb->...
1
vote
1answer
493 views

Create table from array with prepare

Is it possible to create a table with the wpdb::prepare function? I read the documentation and tried to find examples but there where none that helped me. Even creating a table with prepare doesn't ...
0
votes
1answer
30 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
18 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
2answers
505 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
1answer
964 views

wpdb get_results() returns only 2 rows

I am trying to create custom admin widget to present how many users has registered within last days. I have created function as below: function mdbootstrap_add_dashboard_recent_users(){ global $wpdb;...
1
vote
1answer
867 views

Get stock by custom meta field on all Woocommerce variable products

In WooCommerce, I have a custom meta field "Brand" on my products, and each product is assigned with one of the Brands. Now I want to get total stock for each brand from all products and I have only ...
2
votes
5answers
11k views

Export wordpress table to excel

I have created PHP scripts before to export a database table to .xls format like this: $select = "SELECT * FROM tracking"; $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) )...
0
votes
1answer
113 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
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
0answers
32 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..) ...
0
votes
1answer
515 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 ...
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
2 3 4 5
22