Questions tagged [wpdb]
The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database
1,217
questions
-2
votes
1
answer
65
views
How does wordpress link columns from different tables without using FOREIGN KEY or JOIN?
I can't figure how Wordpress tables has been linked by not using FOREIGN KEY?
I tried to understand from this information.
For a custom plugin I want to recreate the terms, taxonomy and relationship ...
0
votes
0
answers
18
views
$wpdb->insert writes a record twice for some reason, when my custom developed plugin calls my class function once
My custom code in my custom (class-based) plugin for some reason, writes the same record twice, when as you can see it's called once. This double write also happens even when I do the same type of ...
0
votes
0
answers
28
views
Skipping all WP functions for a cached version
I started making the following caching codes in order to create an experimental plugin that provides a solution to my own needs.
add_action('wp_loaded', 'buffer_start');
add_action('shutdown', '...
1
vote
1
answer
26
views
Wordpress DB query
I want to capture some data from a WP website I'm building.
The website will show a game to play for each calendar month (12 games). Players can come and play at any month of their choosing. If they ...
0
votes
1
answer
526
views
How to use wp-query to search for posts where post_content OR post_title OR post_name
Hi I'm using WP query in WP 6.1.1 like this:
$posts_where = [
'post_type' => 'page',
'posts_per_page' => - 1,
];
If there are search and status inputs I use those:
...
0
votes
1
answer
37
views
multiple record insert creating many duplicate records
I want to loop over an array and store the records in the database. This is working but for some reason it is creating 30 odd records instead of just 4. I put this code into a very basic custom plugin ...
0
votes
0
answers
191
views
Wp forms wpforms()->entry->update not working on page refresh
Wp forms wpforms()->entry->update not working on page refresh , it only works when i do some change in wordpress dashboard (like clearing cache or updating any post) then only it is updating the ...
0
votes
1
answer
121
views
WPDB query suddenly not working
I have a function that contains a wpdb query. It's supposed to get the image alt text, based on the url of the image. This is the function:
// retrieves the attachment alt from the file URL
function ...
0
votes
2
answers
116
views
How can I update a value of a field depending on outside source?
Say I have a text file or JSON file elsewhere on my domain, that have a simple value, like "yes" or "no". I would like to update a custom field in a database table in Wordpress (...
0
votes
1
answer
36
views
Is there another way to retrieve a post_id from post_meta other than a SQL query?
I'd like to retrieve the post_id from wp_post_meta with a unique meta_key and meta_value. I've tried WP_Query but no values are returned and I'm unable to retrieve the post_id'
$post_query = new ...
1
vote
0
answers
48
views
SQL - How to echo out <div></div> inside of where statement
In my query, is it possible to echo out a php value? If not, is there any way just to pass in the value of the id player_id?
<?php
$New = '<p id="player_id"></p>';
// This ...
0
votes
0
answers
28
views
Putting form result in my database
i have a problem with my wordpress rn.
I did a form in html and js, and i want to put the actual result in my database where i created a table for it.
So basically i did a plugin in simple php that ...
0
votes
0
answers
118
views
Successful ajax call returns lots of whitespace and text of code with 0
I am trying to convert a javascript variable to a PHP variable with ajax. On paper, ajax tells me there aren't any errors, but php doesn't recognize the REQUEST['name_here'], and every time I try to ...
0
votes
0
answers
45
views
Woocommerce permalink URL change in DB
I am changinf URL structure and product URL on the wwebsite.
Problem is this:
When I change permalink structure on the WordPress admin, it creates directly new URL with new structure for each product.
...
0
votes
0
answers
29
views
Uploading to Wordpress Database
Hope everyone is doing great. I have a small issue with uploading information to the wordpress database. I created a new table without the prefix. I created code based on what I've learned in ...
0
votes
1
answer
32
views
$wpdb:insert, more arguements in $format array than in $data
I'm making some customizations for a website, and I cam across this piece of code of a theme:
$wpdb->insert(
$table_name,
array(
'user_id' ...
0
votes
0
answers
94
views
Warning: Undefined property: wpdb::$question_overview in C:\Wamp.NET\sites\proxyvragenmodule\wordpress\wp-includes\class-wpdb.php
My question on stackoverflow was asked on the wrong part of my code
I have an error that ive been dealing with since forever.. Im making a question viewer in wordpress and it shows this error
Warning: ...
0
votes
2
answers
247
views
WP_Query post_tilte search in posts table
Here is my array which I am trying to get "apple" keyword in post table but it can't work like I want. Please let me know what is wrong with my array?
Array
(
[paged] => 1
[...
0
votes
0
answers
31
views
wpdb->prepare creates random string for % character [duplicate]
I have a query like this,
$query = "... user LIKE '%-guest-%' ...";
And when I implemented wpdb->prepare in my query, % characters replaced by random strings. I found solution to ...
0
votes
0
answers
99
views
WordPress / PHP: Check if column has value and then check if value in array
I have a table called wp_invites which contains a list of names (and other data) for those invited to an event. Below are 4 rows from the table:
id
handler
lead_name
party
reference
...
3
votes
2
answers
527
views
How to create a fully functional user registration in WordPress?
I used many user signup plugins for users registration and they did good job, but the problem is, each website collects different data through user registration forms. In my case, the data collected ...
0
votes
0
answers
44
views
How to check record is exist or not in WordPress CRUD Operation with $wpdb
I have been trying to custom CRUD Operation for in Wordpress Page Template, Where i need to handle CRUD Operation but I need to I need to check whether record is exist or not before Insertion.
Here is ...
0
votes
0
answers
24
views
Table wont load into WPDB
Hi im trying to add a table into my WPDB and its still redirecting to an older table (that i have deleted) despite me using the same name it shows this error
WordPress database error: [Table '...
0
votes
1
answer
354
views
I have an error WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version
Hello im new to WPDB and this is my error
WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use ...
0
votes
2
answers
45
views
inner-wrap div pushing custom table far down on page
I am working with code in a custom child-theme. My goal is to pull data from the wpdb and display it as a custom table.
I have created and populated the custom wpdb table with the relevant data, and I ...
1
vote
0
answers
55
views
use wpdb object on other file
I need to connect my wordpress site to another database that is stored on a VPS, I also want to use this connection to query data and show it on my wordpress site, I see that I can connect to the ...
0
votes
1
answer
62
views
Get count of rows based if column exists in two different tables [closed]
I have two custom tables which both contain a column called reference.
wp_invites
id
lead_name
reference
1
John
fRgOeRkFeHIm
2
Alex
WtRA7T7NFdYW
3
Jason
IGr0ZhaCbojD
wp_rsvp
id
accepted
...
0
votes
0
answers
14
views
$wpdb how to make a record lookup
I have made a lookup form, where 2 inputted values, Selecting a Class, and Date, are prompted. Once the values are selected, then the First and Last names matching the records will be displayed.
I ...
0
votes
1
answer
947
views
How to redirect to a page after submitting form data?
I have a custom form which posts data to wpdb.
Currently, after form submit, my form keeps the user on the same page, but I'd like to redirect them to a thank you page.
Here is how the form is set up ...
0
votes
0
answers
28
views
How to get data (not value or name) from radio options to POST to database
I have a set of options that are generated based on database count. For example, if a group has 4 members, 4 radio option pairs of yes and no will show:
Name 1
- Attending? Yes / No
Name 2
- ...
0
votes
1
answer
93
views
Can't send form data to wpdb when URL has query string
I have a table called wp_invites which contains a list of invitees. This table contains a column called reference, which is added to the URL as a query param in order to customise their invite (i.e. ...
0
votes
1
answer
69
views
query_vars doesn't return query string (trying to get data from $wpdb)
I have a ref query string which matches rows in my wp_invites table.
In my wp_invites table, I have the following columns:
lead_name
reference
Let's assume here is one of the rows:
Lead name: ...
0
votes
0
answers
55
views
Error resetting database index using ALTER TABLE in $wpdb->query
I'm running a Cron job every hour that clears all posts of a particular CPT and then re-inserts data by accessing a third party API.
I'm worried that this will lead to huge indexes, so I would like to ...
1
vote
1
answer
162
views
get_post_meta bringing back results, but $wpdb->postmeta doesn't
I'm trying to discover if post exists, based on post_title & metadata post_language.
Until now, the best way I discovered, was using methods appearing in posts like this one, this one, or this one....
0
votes
1
answer
61
views
Wordpress Ajax - looping data into a table
Can anyone tell me what I did wrong? I made an ajax call in wordpress to loop through data to display the results on a table.
Here is my php:
function DisplayInfo() {
global $wpdb;
$...
0
votes
0
answers
58
views
$wpdb Ajax not redirecting to main page
I'm having difficulty with redirecting a page once a person submits data. I made a form, and when the user clicks 'Add student', the data would be encoded through json, stored in the database. The ...
0
votes
1
answer
213
views
Changing regular db connection to $wpdb
I am working on a wordpress site, and started implanting a CRUD database. I coded out an example that works perfectly on my localhost. However, I am working with file mangaer in cpanel, and am having ...
0
votes
0
answers
13
views
Site uses wpdb to fetch meta_keys but just displays first meta_key from a page (the post uses the same meta_key "filmmaker" more than once)
My page should display all filmmakers, that have been tagged as "filmmaker" in my posts. I do have posts that feature more than one filmmaker (meta_key = filmmaker) in custom fields, but ...
0
votes
0
answers
86
views
$wpdb The query does not contain the correct number of placeholders
I am trying to push some data to a custom table in my Wordpress install, but I am getting the error The query does not contain the correct number of placeholders and I'm not sure why. Here is my query:...
0
votes
0
answers
76
views
WP Recommended Table Exclusions?
I just re-designed my WP work flow to utilize 2 bash scripts (push.sh & pull.sh) that I wrote that will push/pull my files with git, upload/download & import/export my dbs using rsync and wp-...
0
votes
1
answer
155
views
update $wpdb one query
Is there a way to change mysql directly in wordpress just 1 operation without needing 2 operations: query and update?
I am facing problem of multiple concurrent transactions impacting point_user
I ...
0
votes
1
answer
170
views
How do I change the datetime format from ( 'y-m-d' ) to ( 'd m y' ) [closed]
I have code that finds the date a page was last updated:
<?php global $wpdb; $psm_mod_datetime = $wpdb->get_var("SELECT post_modified FROM $wpdb->posts WHERE post_title = 'Current ...
0
votes
0
answers
51
views
Need help creating asynchronous data scraper in WordPress
I need some help on a data scraping script I've been working on. I want to create a script through which content can be extracted from a page.
I fetched the page via wp_remote_get() and ...
1
vote
0
answers
19
views
Output: "Array" [closed]
I added a table in the database which collects names through a form.
I want to output the latest entered name on a different page than the one which contains the form.
In order to print the data I ...
0
votes
1
answer
31
views
Display current ranking of post as a number in post title
I have a page where people can rank stuff. My posts are ordered by the current ranking which is stored as a meta key in post meta.
Now i want to add the current ranking spot within the title of the ...
0
votes
1
answer
154
views
Trash Bin for Categories?
I have a cat_notice taxonomy, where there are several categories and one of them the slug is 'trash'. In this case I created a link and I needed that when I clicked on this link I would take the ...
0
votes
1
answer
61
views
Is it important to have integers inserted using %d rather than %s?
Is it important to have integers inserted using %d rather than %s?
I have a situation where there is a large number of fields and values. When database changes are made, it is difficult to match all ...
0
votes
1
answer
122
views
check that the data exists before sending it to wpdb
When I send data to wpdb from form I can have some empty fields.
How can I add conditions to array of data inside array or before insert wpdb to send only filled fields ?
The fields concerned (for ...
2
votes
1
answer
717
views
$wpdb->get_results(...) with $wpdb->prepare(...) returns empty array despite correct query
My MySQL query is correct, but $wpdb->get_results(...) produces an empty array. Here's my code:
$key = 'user-input-key';
$value = 'user-input-value';
$value = '%' . $value . '%';
$query = "...
0
votes
0
answers
18
views
How to save template data into wp_post table (post_content column)
Is there a way to save template data into wp_post table?
I made a custom template that automatically makes tables and some sentences with the meta-data that users insert in.
I wanted to make users ...