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
90 views

Why doesn't my Table get created?

I am working on creating a table in the DB for a plugin but cannot figure out why the table is not being created. Here's my code: global $ds_swoons_db_version; $ds_swoons_db_version = '1.0'; ...
0
votes
2answers
899 views

How do I modify this wpdb query to include posts that have a post_status of publish and draft?

I'm using the following function to count the number of posts an author has made from a custom post type. <?php function count_user_posts_by_type($userid, $post_type) { global $wpdb; ...
0
votes
2answers
169 views

How to query and update one colum in postmeta table?

I'm trying to make a popularity calculation for all posts, based on page view and date of creation. Initially, there's a default popularity value saved in postmeta. Every hour I want to recalculate ...
0
votes
1answer
731 views

Formatting a date/time returned from a custom $wpdb query

I'm definitely a rookie WordPress/PHP developer, so please forgive ignorance :-) Q: How do I format a date/time returned from a custom query against $wpdb? Here's the scenario: I'm trying to write a ...
0
votes
1answer
1k views

Query and get meta as object(stdClass) on wp postmeta table?

I want to get a groups of data from postmeta table. The postmeta table have 4 colums, meta_id, post_id, meta_key,meta_value. Each post_id has a list of meta_keys. I want to run a query and get a ...
0
votes
1answer
363 views

Subdomain redirect problem

Wordpress is installed my root directory(/root/). I have a subdomain(dammani.techbrij.com) and I want to access some files of main domain from sub domain. I have done following thing: ...
0
votes
1answer
262 views

How do I query a table?

I am using Contact form 7 and the database extension, the db extension creates a table called wp_CF7DBPlugin_SUBMITS. I have 2 forms on my site, I need to know if the user has completed the 2nd form, ...
0
votes
1answer
19 views

$wpdb->prepare with ON DUPLICATE KEY UPDATE

I just took this code from $wpdb Codex page, and modified my existing Insert query: $table = $wpdb->prefix . 'user_req'; $post_id = explode('_', $_POST['post_id']); $user_id = $_POST['user_id']; ...
0
votes
0answers
14 views

How do I count columns on a custom WPDB query?

How would I count the columns of a custom WPDB query? This does work although I need a different kind of output: $sql_assoc = "SELECT * FROM test"; $num_cols = count((array) current($sql_assoc)); ...
0
votes
0answers
41 views

There is way to improve this query? wordpress get post data and some meta data

Suppose we have 2 blog with different database A and B. I want to get some post from Blog B to show them on Blog A. The problem comes when the posts have much metadata (custom field for example) that ...
0
votes
0answers
36 views

Inserting into database from form issue

I'm trying to insert some data into a database before email sent with contact form 7. Currently it doesn't seem to be doing anything. My code is: add_action( 'wpcf7_before_send_mail', 'my_conversion' ...
0
votes
0answers
28 views

Run query once inside a loop

I am trying to prevent to much queries inside a plugin one of my plugins. I have a query inside a function which will output a complete block with some layout elements and an input element which will ...
0
votes
0answers
20 views

Best way to execute custom page-specific mysql queries

I would like to query a secondary mysql database (not the Wordpress mysql database) with page-specific queries. I've seen many answers / tutorials on setting up a secondary mysql database, like: ...
0
votes
2answers
32 views

wpdb prepare: passing varible number of fields as second argument

As i want to manage the NULL fields in my db and wordpress functions doesn't allow to do so, i will need to dynamically generate a query depending on the situation. The problem is that i don't know ...
0
votes
1answer
14 views

looking for a way to allow users to backup the plugin db data(save as)

I have a custom build plugin and I want to add the option to let the user save the plugin data(not using a thirdparty plugin to do this for me). So if a user clicks on the button it will allow them ...
0
votes
0answers
41 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
38 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
20 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 ...
0
votes
1answer
19 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
0answers
31 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
9 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
24 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
0answers
43 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 ...
0
votes
0answers
35 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
25 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
0answers
40 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
543 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
55 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
21 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
37 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 ...
0
votes
0answers
23 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
0answers
71 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
49 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
39 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
59 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

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
62 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 ...
0
votes
1answer
63 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
1answer
223 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
86 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
1answer
165 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. ...
0
votes
0answers
34 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 ...
0
votes
0answers
66 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
35 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
0answers
18 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
0answers
21 views

Any issues changing username from wpdb in admin

I'm building a plugin that will have a custom sign up process built in. I would like the users to be able to change their username if needed, since I am using their email address as the username. I ...
0
votes
1answer
86 views

I'm not able to get access to $wpdb [duplicate]

I'm developing some additional functionality with a jQuery autocomplete form, some custom database tables, and PHP to query the tables. I have it working outside of the WordPress framework using ...
0
votes
1answer
257 views

$wpdb->insert Giving duplicates

I'm getting duplicate entries with this, how can I fix it please? <?php echo "Month". $_POST["Month"]; global $wpdb; $wpdb->show_errors(); $wpdb->print_error(); $wpdb->insert( ...
0
votes
0answers
108 views

Wordpress plugin tables become corrupt

I have written a plugin that creates and uses 3 database tables. On rare occasion, all 3 database tables become corrupt but no other tables in the database exhibit similar conditions. It is pretty ...