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

learn more… | top users | synonyms

0
votes
1answer
39 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
72 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
1k 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
154 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
33 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
49 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
136 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
54 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
44 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
458 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
73 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
350 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
64 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
65 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
181 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
27 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
43 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
52 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
1k 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
110 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
64 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
89 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
46 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
93 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
679 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
136 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
158 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 ...
0
votes
2answers
161 views

Replace Main Query With Custom Query

I want to replace the main query with my own custom query. The thing is I don't want to go through the hassle of manual paging. I know there's a filter posts_results but I'm not sure how to use it ...
0
votes
1answer
81 views

PHP Fatal Error - $wpdb a non-object?

I'm getting many Fatal errors like this in Wordpress 3.6.1, multisite with Buddypress: PHP Fatal error: Call to a member function suppress_errors() on a non-object in ...
0
votes
1answer
297 views

$wpdb sql help. Select post id and post meta value based on 2 other post_meta values

I am trying to select post ids and a post meta value based on the value of 2 other post meta values and from a custom post type. Here is a screen shot of my post meta table. ...
1
vote
2answers
114 views

Exclude subscriber users from user list

I want to exclude Subscribers from a user list. My code is: $users = $wpdb->get_results( "SELECT display_name FROM $wpdb->users ORDER BY display_name ASC" ); How can I change that so ...
1
vote
2answers
71 views

Optimizing Query used for a Shortcode

So, I have this shortcode that produces a list of all published multisite and their pages. The network in question has about 50 sites in it. The problem is that loading the page I put the shortcode on ...
0
votes
1answer
143 views

Query custom taxonomy for category including children

I've using the Events Manager plugin which creates a custom post type of 'event' and a custom taxonomy called 'event-categories'. I have the category 'courses' which has an ID of 43. I also have a ...
0
votes
1answer
57 views

How to stop $wpdb from prepending database name

When I run an UPDATE query using $wpdb, WP prepends the database name associated with the WP installation to whatever is passed in the table name argument. This isn't desirable as my app passes the ...
1
vote
1answer
53 views

301 Redirect Code

I am currently trying to redirect a subdomain.blogger.com blog to a domain located on my hosted WordPress install. The code below is supposed to send a 301 redirect and then make that specific post ...
0
votes
0answers
38 views

$wpdb sort order

$meta_key1 = 'first_meta'; $meta_key2 = 'second_meta'; $postids = $wpdb->get_col( $wpdb->prepare( " SELECT key1.post_id FROM $wpdb->postmeta key1 INNER JOIN $wpdb->postmeta ...
1
vote
1answer
99 views

Search Everything & WP 3.7 update issues [closed]

I have been personally maintaining the Search Everything plugin for WordPress since the authors stopped. I upgraded one of my sites to wp 3.7 today but i get this error when i search: WordPress ...
0
votes
1answer
237 views

Insert two row in wordpress database

Hello I am working on a template where I have to grab some value and insert them in my own created table in wordpress database. Now as I dont know how to insert record in wordpress database , so i am ...
0
votes
1answer
100 views

get data with shortcode

i have a wp db. and i added a table "wp_mapmus" now i want to show these datas on post page with shortcode. But there is an error. and i dont know php very well. i only use same plugins. what is the ...
0
votes
0answers
88 views

why is $wpdb->update() causing a DB error from within wp_set_password()

I have a page-template for my custom theme that enables the user to reset their password from the front-end. I'm calling wp_set_password() and everything runs but the password is not changed in the ...
0
votes
1answer
42 views

wpdb Cannot Access Associative Array Data in a Count Query

I have two records in my custom table. I am trying to use SELECT COUNT(*) AS total FROM tableA but I am not getting the results I am expecting. The code below will echo Array ( [0] => Array ( ...
0
votes
1answer
617 views

WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version [closed]

after wordpress update to 3.5+ i get error in this plugin. I do not understand how to fix it. If anyone can help me with these problem or give me an example of how to fix it here is the full code of ...
0
votes
1answer
162 views

Can I use wpdb to insert query results into a post?

My website currently consists of content drawn from database queries, displayed with php. Specifically, there are 4 modules, each of which queries a different database to get all records that match ...
0
votes
1answer
225 views

after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()

after wordpress update to 3.5+ i get many errors in this plugin. i found that the reason is: http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/ I do not ...
0
votes
1answer
93 views

$wpdb - joining shows no result

For one of my client's WP site, I'm making a plugin, where I'm using the db Query. I've two custom tables dedicated to the plugin: user_req — stores user chosen posts along with some custom ...
0
votes
0answers
24 views

Calculation for each custom post type

I have a code looking like something like this: (It calculates number of registered members for each course) foreach($courses as $course) { global $wpdb; $sql = "SELECT COUNT(*) FROM ...
0
votes
2answers
93 views

Accessing two databases wordpress

I'm trying to access a second database with my wordpress system. To do this, I've attempted to follow the advice found here which seems to have worked for a lot of people. In summary, I'm adding ...
0
votes
1answer
145 views

Delete/replace img tags in post content for auto published posts [closed]

In my blog I have set up auto-publish for posts and I get 5 thousands new posts every day, in this moment I have more than 150 thousand posts. I need a script, or a plugin, or a function to connect ...