Questions tagged [wpdb]
The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database
1,220 questions
0
votes
0
answers
21
views
How can I temporarily set sql_mode=only_full_group_by in $wpdb query?
I'm running SQL queries with GROUP BY clauses using WordPress's $wpdb global object, like this:
$wpdb->get_results("SELECT * FROM foobar GROUP BY foo, bar");
I'm discovering that $wpdb ...
0
votes
1
answer
14
views
get_var not returning a value when the field contains an apostrophe
I am trying to run a comparison on 2 tables based on last names. However, if the fields contain apostrophes, the query returns a blank result. If it doesn't contain an apostrophe, it will return the ...
1
vote
1
answer
288
views
SQL errors when querying for something with apostrophes
I have the below PHP function that queries some custom database tables and outputs the result. This generally works great, except for when I put an apostrophe in the query; for example, "Men's&...
0
votes
1
answer
35
views
Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder
I am getting the following error: Function wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. I have gone through plenty of other similar questions ...
0
votes
0
answers
32
views
$wpdb->get_results() query empty, but same query in phpmyadmin has results
I'm running the following query to get attachment data for a long list of post ids:
SELECT post_id, post_title, meta_key, meta_value
FROM wp_postmeta JOIN wp_posts ON wp_postmeta.post_id = wp_posts.ID
...
0
votes
1
answer
25
views
$wpdb->update is not working until next page refresh. Is there one more step?
When I update a post and then re-get that post to check if it worked, it does not seem to have worked, but it actually did. Is there a purge_db_cache() kind of thing?
$pid = 55276;
$post = get_post($...
1
vote
2
answers
136
views
how to run tests using different db connection
I would like to run tests on a db different from the real one. So I cloned the real db into a new one and tried wpdb::select passing as second parameter a mysqli connection to test db.
$mysqli = new ...
0
votes
1
answer
28
views
wp db request without refreshing the page
want to make database requests like for example "select * from wp_users" to the database without refreshing the page. I am in a wordpress plugin.
Have try already a few things and seem not ...
1
vote
0
answers
21
views
Illegal mix of collations using a function [closed]
I am running into a collation problem when using a function.
My query is this
SELECT CONCAT(PERSON.LastName,', ',PERSON.FirstName) AS 'PersonName',
funcGetStandardValue(PERSON.ProgrammeId) AS ...
1
vote
0
answers
54
views
How to properly prepare a column name if passed to a stored procedure?
I've figured out that I can use %i with $wpd->prepare() to escape identifiers like column names. The thing is that the query I'm preparing is a call to a stored procedure like this. I want the end ...
-2
votes
1
answer
298
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
32
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 ...
1
vote
1
answer
44
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 ...
2
votes
1
answer
4k
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
48
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
583
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
300
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
335
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
37
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
74
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
31
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
52
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
52
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
122
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
574
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
33
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 ...
4
votes
2
answers
2k
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
31
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
717
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
75
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
76
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
92
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
1
answer
2k
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
30
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
139
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
120
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
98
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
303
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
122
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
64
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
400
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
15
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
213
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
240
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
331
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
230
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 ...
1
vote
0
answers
71
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
23
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
39
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
223
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 ...