The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database

learn more… | top users | synonyms

1
vote
1answer
958 views

wpdb->insert multiple record at once

So after I have created the table 'settings-table' i want to add a couple of records to it. This is how I want to do it, not the best way, so I need a better way to do this because I will add more ...
0
votes
2answers
92 views

Short of raw SQL, can I query for multiple attachment metadata that have a given array key?

With raw SQL through $wpdb, I believe that I could do something along the lines of this (untested): SELECT post_id, meta_value FROM postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value ...
0
votes
0answers
40 views

Proper way to trigger a MySQL query via link in a plugin

I am trying to develop a module in my WordPress plugin that will delete an entry from the database. The only issue is related to the trigger action. I've tried to send my users directly to the page ...
1
vote
1answer
26 views

Super administrator db name

As I cant test this(cant find any docs and dont have an multisite setup) I need to know the db name of the Super Administrator. So how is this role stored inside the wp db? It's probably something ...
0
votes
1answer
89 views

WP MS: How to query over the network

I have a WP 3.8.1 Multisite installation with 3 blogs, they're all in one db, prefixed wp_, wp_2_ and wp_3_. In a template in wp_ I try to to display all posts from wp_, wp_2_ and wp_3_ which have a ...
1
vote
1answer
2k views

Delete row of custom table in WordPress using AJAX

From my custom table ($table = $wpdb->prefix . 'user_req';) I'm showing data with $wpdb->get_results() and a foreach loop: I managed to update the database with the individual values from the ...
0
votes
1answer
49 views

wp-postratings: list current user's unrated posts

This is the code I use to list current user's rated posts (I use the wp-postratings plugin on my site for rating posts): <?php global $wpdb, $current_user; $userranking = $wpdb->get_results( " ...
0
votes
1answer
158 views

List users with the most posts in the last 30 days

I'm trying to create a MySQL query to display a descending list of users with the most number of posts over the last 30 days. This is not working with me: $where .= " AND post_date > '" . ...
0
votes
0answers
103 views

Using the same shortcode to show any table from the database

I have a little question for you. I want to create a shortcode that makes a table with data that I have stored in a database. But i want to send the shortcode an attribute, to specify which table ...
0
votes
0answers
13 views

WPDB preparing delete from [duplicate]

I know my variables and functions are ok, it must be the way I have added the prepare that is stopping it working. function delete_record($table, $id) { //deletes a specific record global $wpdb; ...
0
votes
0answers
42 views

$wpdb: how to use a query as a base for another query?

I've got this query: select p.ID, p.post_title, p.post_content, t.term_id, tt.taxonomy, t.name, t.slug, tt.count from bdu_posts p inner join bdu_term_relationships rel on p.ID = rel.object_id inner ...
0
votes
4answers
189 views

Displaying post excerpt using wpdb query

I'm using a modified version of the code from a question (Get WordPress Posts Grouped by Month) to group my posts by year. Everything is working fine, but I'm having trouble getting the post excerpt ...
0
votes
1answer
131 views

Are term_taxonomy_id and term_id the same?

I have a custom query where I need a JOIN because I want to COUNT all the posts of a specific category. So I checked the tables and I found out that table wp_term_relationships contains a reference ...
0
votes
0answers
61 views

Update tags to 10,000+ posts with wpdb?

I have over 10,000 posts on a site which all need to have a tag added to them. WP_Query is either running out of memory or timing out on my server and in the past running large queries with this ...
1
vote
1answer
93 views

What's the purpose / logic of split_the_query in WP_Query->get_posts

In the get_posts method of WP_Query, there's a section relating to split_the_query The logic of split_the_query is $split_the_query = ( $old_request == $this->request && ...
1
vote
1answer
59 views

WPDB query - decrypting DB data

I am trying to grab data from the DB using WPDB but I am stuck on how to decrypt the data e.g. The data is stored as: a:2:{i:0;s:2:"92";i:1;s:2:"71";} I want the 92 & 71 as that's my post IDs, ...
0
votes
2answers
2k views

How to return number of found rows from SELECT query

I wrote a function which is supposed to return the number of rows found in a SELECT query but it always either seems to return 0 or an array. I have been messing around with this for about an hour now ...
0
votes
1answer
273 views

Add row to custom database Table and delete all rows older than 1 day

I'm editing a view counter plugin so that it logs the IP of every user that viewed a post. This is to prevent them from refreshing the page and thus creating artificial views. The part I'm having ...
0
votes
0answers
74 views

Order users by 2 custom fields in wpdb query

I've created a WordPress members site, each member is a user with the role of subsriber and has extra information set as custom fields - ie: address, contact details etc. I have the users output by ...
0
votes
1answer
92 views

wpdb select from using array as search parameters

Similar to how you can insert into an array using code such as $wpdb->insert( $table_name, $inputs); //where inputs is an array I want to do a sql select statement with code such as ...
0
votes
1answer
335 views

insert image alongwith with custom data via a frontend form

I use wordpress as a cms. I wanted to insert custom data via a form from the frontend in my wordpress site and then echo it on a page somewhere. After learning from here and there I am able to put ...
0
votes
1answer
42 views

$wpdb in php 5.5

I am helping a friend update their website and move it over to a new server. Their old server is running php 5.3.6-13 and the new site is running php 5.5. There is a custom plugin that uses $wpdb ...
0
votes
0answers
100 views

Querying the DB to get sum of column from custom meta box (only published posts)

I am trying to get the SUM total of a custom meta box, from all published posts, from a custom post type. By using $wpdb I am able to get the sum from all of the posts (published and otherwise), but ...
0
votes
0answers
3k views

AJAX with Selectbox Plugins (Select2, Chosen, Selectize)

I have been searching all over the internet for tutorials on implementing AJAX actions from jQuery selectbox plugins such as Select2 , Selectize and Chosen. (these plugins look better than the inbuilt ...
0
votes
1answer
247 views

Getting featured image with direct $wpdb within plugin

I'm using a customized version of the Last Viewed Posts plugin to grab recently viewed releases on my record label site. The code I'm using grabs an attachment image but it is not always the page ...
0
votes
0answers
42 views

How Can I Put Meta_Compare in the Database-Query?

Yes, I know that this can easily be done with built in wp_query but I need this in Wpdb query. I have a custom field and I need to display posts where this field does not exist. By the way can I get ...
0
votes
0answers
68 views

$wpdb->prepare - supporting multiple search terms

I am trying to write an escaped SQL statement, for example: $sql = 'SELECT * from TABLE where column LIKE %searchterm% AND column LIKE %searchterm2%'; Except I don't know how to handle it, as I do ...
1
vote
2answers
253 views

Why does $wpdb return strings for mysql integer values?

I find it very inconvenient and hard to understand that the default behavior of the Wordpress db-interface is to convert all integer (and float?) types to strings. e.g $wp_posts = ...
1
vote
1answer
71 views

Confused by $wpdb->prepare

I am attempting to use $wpdb->prepare to protect against SQL injection attacks and am lost. I have the following snippet below which checks the h_transactions table for a transaction id. If it ...
0
votes
0answers
26 views

After importing data to new DB with new name, receiving a constant MySQL warning

I've just spent several hours trying to understand why a WP install is really slow, I tracked it down to the database and realised everything in the db was just running super slow with the debug bar ...
0
votes
1answer
49 views

Create new database through static page code

I want to create a new table in current database of word press through create a static page. I write code for this as below, but there was no result. Why is that, and how can I get this right? ...
1
vote
1answer
641 views

wpdb prepare syntax

$arr = []; array_push( $arr, 'wp_table', 1, '2013-12-24', 3, 'NULL'); $sql_prepare = "INSERT INTO %s (id, datea, one, two) VALUES (%d, %s, %d, %s) ON DUPLICATE KEY UPDATE one = VALUES(one), two = ...
0
votes
0answers
80 views

Wpdb generates too many queries

I googled for hours, then found some codes on stackexchange (http://wordpress.stackexchange.com/a/108279/108270) and created the codes below. I'm trying to get alphabetical A-Z posts lists (e.g. A B C ...
0
votes
1answer
559 views

How to return count of custom post type posts with a specific custom field value via $wpdb?

I am trying to get count of a custom post type with a specific custom field value from wpdb without doing a WP_Query or get_posts since I think it is more resource efficient and I need to return 10 ...
0
votes
1answer
71 views

Get null from POST

I have problem with my code. I don't know why all my $_Post have null at the end.This is my code: function ow_display_user() { wp_enqueue_script('jquery-ui-datepicker'); ...
0
votes
1answer
77 views

Wordpress' work or execution flow manipulating $wpdb

I have read about overwriting global variable $wpdb and connecting to a second database this way ( Search another database with wp_query using new wpdb ) so one could e.g. use WP_Query on 2nd DB. ...
0
votes
0answers
15 views

How to change location, charset in Wordpress query [duplicate]

I have strange question. How Can I change or set a sql char set in wordpress. In wp_config.php I have: define('DB_CHARSET', 'utf8'); define('DB_COLLATE', 'utf8'); In my plugin I have this: global ...
0
votes
1answer
272 views

$wpdb and MySQL Create Trigger

Do $wpdb's methods not accept a MySQL CREATE TRIGGER query? I tried it with $wpdb->query( $sql_trigger ) over and over again without success. Throwing the create-trigger-query on phpMyAdmin the ...
0
votes
1answer
29 views

remove all custom post created

i will automatically create a lot of post with the wp_insert_post function <?php wp_insert_post( $post, $wp_error ); ?> all those custom post type will be call "house" and then after some ...
0
votes
1answer
54 views

Querying multiple meta_keys in Wordpress SQL query

Here's my Query... I'm looking to narrow this query down to users of one specific role ("meta_key = 'wp_capabilities' AND meta_value = 'employee'")...how do I add that additional conditional to this ...
0
votes
1answer
75 views

How to optimize multiple insert into wordpress database

I had main file with my plugin and the another file with sql command. In the second file I create two tables and write data to one of them. But I have problem with. In my private computer everything ...
1
vote
3answers
2k views

Query to sort a list by meta key first (if it exists), and show remaining posts without meta key ordered by title

I'm working on a custom taxonomy term page template where we want the items that are connected to the term sorted by a publication date (custom date field) - and if there are multiple items on the ...
0
votes
1answer
182 views

get unserialized array without using get_option()

I'm working on a WPMU plugin that cycles through tables in each blog on the network. I can't use get_option to pull the settings array out of the wp_n_options tables, so I'm trying to do it by ...
-1
votes
2answers
72 views

Fixing plugin for wpdb::prepare

A previous developer created a plugin for a website I manage and everything seems to work okay, except I'm getting the error "Missing argument 2 for wpdb::prepare()". I understand that the arguments ...
0
votes
1answer
114 views

get_var result empty for query of custom table in plugin admin

(There are a lot of related questions to this but none I can find with answers that have worked.) get_var returns empty when I query a custom table from a custom plugin for multisite. What am I ...
0
votes
2answers
47 views

Help setting up a sql query

I need to list out specific custom field items that contain an associated custom field entry. For example, the custom fields are named "type" and "food". I would like to list out all of the breakfast ...
0
votes
1answer
110 views

access JSON results from wordpress database with wpdb

I have JSON results from Google API added to to wp_options table. At this point I just need to echo the specific elements. Namely, the coordinates. The option_name I have is py_menu_item. One of the ...
0
votes
1answer
1k views

How to delete all records from or empty a custom database table?

I can't seem to find a simple reliable way to do this - perhaps?: // delete row ## global $wpdb; $delete = $wpdb->query( $wpdb->prepare( "DELETE * FROM `wp_table_name`" ) ); ...
0
votes
1answer
359 views

$wpdb->get_results not returning an array

I haven't really messed with $wpdb before, but I'm stuck hard on one part. I'm trying to get the values returned in an associative array. I've tried both of these $datarow = ...
0
votes
1answer
296 views

How to fetch records from database WordPress

index.php: <?php $new=$wpdb->query("select * from wp_posts where post_title='Auto Draft'"); $new1=mysql_fetch_row($new); echo $new1[0]; ?> How to fetch record from database? How ...