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
0 answers
8 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
12 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-...
  • 145
0 votes
0 answers
18 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
21 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
19 views

Wordpress ajax response save into database

I have this code which grab playlist from youtube and through foreach and ajax send data to wordpress function to save into database. IT is not working, i know somewhere i'm doing wrong but unable to ...
0 votes
0 answers
30 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 ...
0 votes
0 answers
10 views

How do I have a user upload a blog post and then retrieve that to display in a card on the site?

Hello everyone, this is my first time on a forum like this so please be gentle! I will try asking and answering as accurate as I can. I have to create a site in which you can send in some data using a ...
  • 1
1 vote
0 answers
14 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 ...
  • 11
0 votes
1 answer
20 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
34 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
30 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 ...
  • 259
0 votes
1 answer
23 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 ...
  • 11
0 votes
0 answers
42 views

MySQL Query Returns Array () In Shortcode

This is in my theme's functions.php. I have an external MySQL database that I'm connecting to in WordPress with the following code, and I'm attempting to create a shortcode that shows the total of a ...
0 votes
1 answer
103 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 = "...
  • 83
0 votes
0 answers
16 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 ...
0 votes
0 answers
27 views

WordPress get last inserted user id

I want to disable user_login field into my CMS. They are register only their email adress. I think to create secret user login by programmatically. I think for accessibility and manageability also I ...
  • 290
0 votes
2 answers
26 views

Cannot get wpdb data (Error in a simple fuction) [closed]

I'm using Cryto Plugin and want to get coin price data from plugin db. For easy practice, I'm trying to get BTC data. <?php function get_coin_price($coin_symbol) { global $wpdb; $coin_price = ...
0 votes
0 answers
24 views

Can't find out why dbDelta dosen't create my table

I have a function which needs to create a new table an d i can't see for the life of me why it dosen't create the table: function afdv_create_delivery_table ( $id ){ global $wpdb; $...
0 votes
0 answers
48 views

Add posts to custom table in database instead of wp_posts

What the code does: Imports posts, loops through all the posts and calls wp_insert_post to create a new posts for each import. Objective: Import posts and store them in another table, not under the ...
  • 189
0 votes
1 answer
64 views

how to get serialized post meta

I have posts that have video content and these videos stored in database like this (serialized) a:1:{s:9:"video_url";s:0:"";} This serialized data have post video urls but can ...
1 vote
2 answers
285 views

wpdb get_results() and prepare when to use prepare?

so if i have a function that gets terms from the database ( not the user ) do I need to use prepare first ( before get_results() ), or some sort of data sanitizing?
0 votes
1 answer
150 views

How to left join meta in queries [closed]

I have a query something like //read products with thumbnail and sku SELECT products.*, pm1.meta_value as sku, p1.guid as thumbnail FROM `wp_posts` as products LEFT JOIN `wp_postmeta` as pm1 ...
  • 111
0 votes
1 answer
38 views

Isn't Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}

I'm trying to count rows in sql table using SELECT COUNT(*) for the post view count. My code is function get_post_views($offset=0, $post_id){ global $wpdb; $get_visit_query = "...
0 votes
0 answers
63 views

wordpress mysql / wpdb ajax load more for terms help

Can anyone pls assist me with my problem. I am not asking for code, but even some guidance as to how to get this working. I have tried many ways, to get my terms to load using ajax load more and seem ...
  • 16
0 votes
0 answers
88 views

Get child product categories from parent product category for CUSTOM TAXONOMY archive page

Can anyone help me as LoizTheAztec pretty much covered most of what I need here with his very helpful answers. What I need to do is alter this further, and rather than it being on a Product Cat ...
  • 16
0 votes
0 answers
42 views

Improve performance of slow query

I'm using this query to obtain all the products buyed by user and works but query monitor says me that is a slow query (above 0,5 sec), there is a way to fix this? Here the db query: $result = $wpdb-&...
0 votes
1 answer
33 views

Sql formatting for post data within function

I'm calling a function through ajax in my site, and within the function that's being hit I'm taking the data (in this case it's a search term) and putting it into LIKE statements in sql: $...
  • 113
1 vote
0 answers
32 views

Creating mySQL procedure with $wpdb

I'm trying to create a calendar table upon activation of a custom plugin I am building. The procedure script I am using can be seen here: https://gist.github.com/bryhal/4129042 The first part that ...
1 vote
1 answer
71 views

WPDB If primary key already exists, add +1 to integer field

I need a system in which I check if a Primary key (string) already exists. If it does, then I want to add 1 to a second column. If it doesn't, then I want to add a new row and set the second column ...
0 votes
1 answer
31 views

get specific values from WordPress meta_value

a:1:{s:9:"toys_item";a:1:{s:16:"toys_item_ranger";a:11:{i:0;s:31:"2 x Seadoo GTX 230/IBR Jet-Skis";i:1;s:30:"1 x HD Runway 10′ Waterslide";i:2;s:14:"4 x F5 ...
0 votes
1 answer
137 views

$wpdb->update() always need a second try

I will use a custom endpoint of REST APi to update fields in a custom table. Therefore, i wrote this function: function update_table_single($request = null){ global $wpdb; $data_key = trim($...
  • 103
0 votes
1 answer
83 views

How to run wp_insert_post() & wpdb on the background?

I have created a code to fetch data from a remote API then echo certain data & import those data into a post type using wp_insert_post() & post meta** using wpdb->query(). Here's my current ...
0 votes
0 answers
49 views

Counting Posts with multiple taxonomy and terms condition using MySQL and AJAX

I am trying to get the number of posts with multiple taxonomy and terms using MySQL and AJAX. but I cannot get the desired result with my query. I derived my query in this wpdb query and sadly it ...
1 vote
1 answer
175 views

Why is variable not working on custom sql query using wpdb?

Im trying to insert bulk post meta in a single query, however when it wont insert data if i use variable on it. Here are my codes so far. I added comments on which codes work & which does not. (...
0 votes
1 answer
71 views

Passing in MySQL prepare statement parameter separately throwing error

I have some code that looks like this: $stmt = $wpdb->prepare("SELECT * FROM <tablename> WHERE user_id = %d", $user_ID); It seems to work fine... However, I have some queries that ...
0 votes
0 answers
47 views

Convert a column of a table containing an Array as response in HTML

I am trying to iterate through the following information saved in a table in my database: wp_table_log id_envio int(11) order_id int(11) fecha datetime request text response text ...
0 votes
1 answer
188 views

Which is faster wpdb & get_row or wp_query & ge_post_meta?

Im planning to make a private api and i was wondering which one should i use go for my datas. wpdb & get_row with my custom sql regular wp_query & get_post_meta() Im wondering if it's better ...
0 votes
0 answers
103 views

Database SQL query error

I am trying to run below query. $sql = "SELECT * FROM `wp_podsrel` WHERE `related_item_id` =$user->ID AND `pod_id` = 17 AND `field_id` = 25"; $results = $wpdb->get_results($sql) or ...
  • 397
0 votes
0 answers
44 views

$wpdb->insert not inserting all rows

I'm doing a for loop and in the loop inserting items into a custom table in WP. I did some logging and it is inserting each post(returning a 1 for true) and even returning an ID, but when I look in ...
0 votes
0 answers
49 views

How to pass an input value into wpdb->Prepare

If I hardcode $find = 'Feb', I get results, if $find = $searchq, I get Feb searchq Birthdays in Feb Feb find global $wpdb; $path = $_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/twentytwelve-...
0 votes
1 answer
736 views

ob_end_flush(): failed to send buffer of zlib output compression (0) in external php

I have this little php I call from jqGrid url that I use inside an admin's wordpress plugin: require_once($_SERVER['DOCUMENT_ROOT'] . '/xDl21my20/wp-load.php'); remove_action( 'shutdown', '...
  • 103
0 votes
0 answers
38 views

wpdb insert formatting for date in array

I have this simple wpdb->insert: $this->wpdb->insert( 'tablename', array(...., field1 => 'blahblah' , 'birthdate' => (isset($this->dob)) ? esc_attr(date('Y-m-d', strtotime($this-&...
  • 103
0 votes
1 answer
91 views

See if the email exists or not

I have extracted a bunch of emails using PHP IMAP connection and assigned those emails to a custom post type. Here's the code how I assigned those emails to custom post type. $total = $emails->...
0 votes
0 answers
30 views

How capturate wpdb exceptions?

If, in a function. I execute this (wrong) query: try { return $this->wpdb->get_var('SELECT * from mickeymouse'); //intentional bug: there isn't a table "mickeymouse" } catch(\...
0 votes
1 answer
112 views

Search and replace not working for ACF Images

I just connected a staging site from IP Address to a live domain. I ran search and replace on everything from IP Address to domain name. I mistakenly added the trailing slash after the domain name ...
  • 162
0 votes
0 answers
21 views

How do I get specific readable results from this query and array results

I am running the following query to get an array of WP revisions which includes custom fields revisions. This seems to be working and spitting out the array and there are two values I am wanting to ...
  • 1
0 votes
2 answers
160 views

Conditional sorting with variable using WP Query

I have for example this posts in WP: Name ID Date JohnA 6 01012020 JohnB 7 01022020 KateA 7 05052021 SamA 4 01022020 SamA 4 01022022 How I can order by date, but also put posts with ...
1 vote
1 answer
281 views

Wp_query function to search from product_title 'OR' product tags name

I am looking to show search results from either product title or product tag name. I have implemented the product title search through the below code, but I need to add tag name search also into it. ...
0 votes
0 answers
34 views

Wordpress SQL Prepare

i'm trying to adapt this code to also take in to account specific categories and custom post types, so it would give me select dropdown populated with unique custom field values, from a specific post ...
0 votes
0 answers
31 views

How to display specific data from a custom table to logged in users with a custom role

I have constructed a custom plugin that stores data in a custom DB table relating to the viewing activity of users who have a custom role of 'attendee' on a custom post type page called 'presentations'...

1
2 3 4 5
24