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
2answers
14 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
44 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
23 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
11 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
34 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
14 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
24 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
16 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
13 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
30 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
25 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
37 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
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
15 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 ...
1
vote
0answers
22 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
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
10 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
35 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
37 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
20 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'] = ...
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
17 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
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
24 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
56 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
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 ...
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
35 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
27 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
31 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
14 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
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
2answers
19 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
24 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
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
275 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
46 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
14 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 ...
2
votes
1answer
147 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
37 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
16 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
23 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
49 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
36 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
50 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
21 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
24 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
32 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 ...

1
2 3 4 5
22