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

learn more… | top users | synonyms

1
vote
2answers
514 views

wpdb Custom Meta Data with 2 conditions

This is one of those problems that I've spent way too much time on, and there is probably a VERY simple solution that I am missing. Any help would be greatly appreciated. I am trying to populate a ...
1
vote
0answers
180 views

How to display users with posts published between two dates (Sorted by Post-Count) [Multisite]

I'm trying to make a list of users who have published posts within two given dates. My attempts using WP_User_query just work for one blog ID and takes time to load because it runs through a lot of ...
0
votes
3answers
337 views

Retrieving custom field array value through db query

I'm trying to query the database for posts based on multiple custom fields. This is easy enough with the code below if values are simple: $querydetails = " SELECT wposts.* FROM ...
0
votes
1answer
465 views

Best practice to import user base (subscribers) from one website to another?

I want to import users from a Wordpress installation to another. Same domain, but complete different websites. Website A (old, 700 users): running WP3.0 plain installation + BBPress 1.x Website B ...
0
votes
2answers
358 views

wordpress $wpdb works only once

I am working on a plugin that needs to run many different queries. I created a class that has many functions and all these functions runs different queries. A DAL basically. Now when I call these ...
0
votes
1answer
153 views

Use Loop or direct database query?

In one of my form input, the options are a list of posts. I can use the loop to get the posts, but, getting things from database table is faster, right? I see plugins sometimes use db directly, ...
0
votes
1answer
1k views

$wpdb->num_rows doesn't work

I'm trying to perform some checks on custom fields before they are saved on a db. So I decided to use an add_filter as it does this between browser and db. Here is my code function ...
0
votes
1answer
117 views

Insert data through a script directly in the db

is it possible to insert data through a script or HTML site into the wpdb and this will show up as normal article in the, the same as when I use the 'create new post' page? Which tables are affected ...
0
votes
1answer
325 views

Can't seem to get set_blog_id working, it just doesn't reset the blog ID

Trying to iterate through a list of the sites and I can't seem to get set_blog_id working. Here's the sample output: Array ( [0] => stdClass Object ( [blog_id] => 2 ) [1] => stdClass Object ( ...
1
vote
1answer
527 views

Retrieving multisite blog IDs, somehow failing to foreach them properly

Working on a directory listing and have cobbled together the shortest query I can. It appears to return the listing ok (I think) but the foreach is somehow failing to process the array properly. Can ...
0
votes
1answer
59 views

Linked pages from plugin on front can't see $wpdb

I obviously need more knowledge re this one. From my plugin. I have a custom main page which displays my custom db data table of a list of stores. Each store has a "link" ie using a href eg. <a ...
0
votes
2answers
310 views

How to obtain a reference to $table_prefix in $wpdb object

I need to call the WordPress options table and pull some data. However, the table name may be different (typically wp_options) depending on whether the default table prefix was used on installation. ...
1
vote
2answers
493 views

Mysql query LIKE not working

I'm using this code. $blog_list = $wpdb->get_results( "SELECT " . $extra . "blog_id, last_updated FROM " . $wpdb->blogs. " WHERE public = '1' AND archived = '0' AND mature = '0' AND spam = '0' ...
1
vote
1answer
929 views

passing variables as parameters to stored procedures via wpdb from php-script

i am having a slight problem with passing php-variables to a stroed procedure call from a php-script. Here comes the details: This is how it works very perfect - passing the params as string: ...
1
vote
1answer
750 views

using $wpdb to insert a form into a post

I am wanting to take the following form, and use $wpdb to insert it into a post. I have tried reading the class reference page INSERT rows, but I don't really know what should be referenced. I am not ...
2
votes
2answers
658 views

Query WP data with the WPDB API from outside WordPress

I'm working on a project with WP, a bit like a plugin, but not quite one. I'm encountering an issue, when trying to include a file that contains some custom SQL functions in a class, in a completely ...
4
votes
1answer
325 views

Query causing load because of SQL_CALC_FOUND_ROWS post counting?

I found this query causing some load in the server, my hosting provdier asked me to look on it. SELECT SQL_CALC_FOUND_ROWS wp_posts I think this select no. rows found in wp_posts table.. but i ...
0
votes
1answer
290 views

Jeditable Plugin working as it should - scope issue?

I am using the Jeditable plugin to enable inline editing on a table inside the admin area, generated by a small plugin I've written. (http://www.appelsiini.net/projects/jeditable). Basically ...
0
votes
2answers
449 views

Trouble inserting string containing quotations marks with wpdb in save_post hook

I'm having trouble with inserting a string which is containing quotation marks in wordpress via wpdb. I've written a hook for save_post and trying to write the post_title in a table via wpdp->update. ...
1
vote
3answers
2k views

Help With MySQL to WPDB Query Conversion

I have a problem. I've got a PHP script that tracks individual file downloads, and I'm looking for a way to display that number in individual posts. I've got a half-baked solution- a plain ol' MySQL ...
0
votes
1answer
285 views

What's wrong with this wpdb query?

I want to select some tags with the same term_group, I tested it in phpadmin, the query get the correct result, but once add $wpdb flavor, it returns an empty array. Any advice? $primary_tag_id = // ...
1
vote
1answer
848 views

Programmatically Creating Page using $wpdb and getting 404 error

EDIT: Turns out I had a permalink issue that was causing the 404 error. Original Posting below: I am creating a page programmatically using $wpdb->insert() and the resulting page returns a 404 ...
1
vote
2answers
397 views

Bootstrapping Wordpress MultiSite Outsite of Wordpress - No $wpdb

I'm working on a plugin for a system to use Wordpress as the authentication backend, so that I can use my existing Wordpress users in another application. The plugin works great when running in single ...
3
votes
2answers
6k views

$wpdb->insert not working in any way

I know this type of question has been asked over and over, but I couldn't find a solution for my problem, so I hope you can help me. I am using WP 3.3. and I have created a custom table. Now I want to ...
0
votes
1answer
421 views

paginate_links on custom query in admin - 'sufficient permissions' error

I have created a page in my admin with this custom query: $rows = $wpdb->get_results("SELECT * FROM ej_feedback ORDER BY createdtime ASC"); I have made it successfully paginate as required in ...
0
votes
1answer
564 views

$wpdb->flush(); breaks the loop

I am using $wpdb->flush(); at the base of my page in an attempt to prevent the query executing multiple times due to caching however it seems that it isn't flushing the most recent query but the ...
0
votes
1answer
809 views

wpdb->get_var - count author posts, meta value

In an author.php template, i count the author post in a custom post type with $wpdb->get_var, $post_author = $curauth->ID; //author id $count = $wpdb->get_var( "SELECT COUNT(*) FROM ...
0
votes
1answer
326 views

$wpdb->get_var next var?

This is giving the same views value for each post how would I grab the next var for each post? <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <a href="<?php ...
5
votes
1answer
531 views

Matching database content types to PHP types

The $wpdb query methods return all query results as strings. For example, an 'ID' column would return a string value like '42' instead of an integer 42. Is there a way to configure the WP database ...
2
votes
1answer
247 views

Multipart/formatted MySQL query problem

I'm creating a plugin and I want to automate the creation of a MySQL Trigger on a table. The problem seems to be that $wpdb->query doesn't appear to accept either multipart statements and/or formatted ...
1
vote
1answer
758 views

Custom Query num_rows returns wrong amount

So I have a custom query that fetches all posts in a given category. I am trying to get the number of rows returned but it is giving me the wrong number. Instead of 11, I am getting 14. Does anyone ...
0
votes
1answer
304 views

How can I change my meta_query to SQL wpdb query?

I want to extract post related to 3 meta_data fields called bed_value, bath_value, rob_value the variable data is $bedrooms, $bathrooms, &rob, I got some confused with join and like structure. The ...
0
votes
4answers
1k views

Trying to display posts by authors in with specific user meta

Ok here's the solution: <?php $wp_user_search1 = new WP_User_Query( array( 'meta_key' => 'state' , 'meta_value' => 'NM', )); $listers1 = $wp_user_search1->get_results(); $lister_ids1 = ...
1
vote
1answer
317 views

using custom taxonomies on non wp table?

I'm building a program registration system that will have a complex data structure. There are programs (custom post type, CPT), teachers (CPT), registrations (custom table and meta table), payments ...
7
votes
8answers
4k views

what is the way to see the currently executing query in wordpress?

I am working on wordpress which is new to me Now I have been provided with site completely designed in wp But the problem is I am unable to search the query for each functionality/page I found ...
0
votes
2answers
274 views

wpdb function insert doesn't work

It just won't insert anything, if I echo it, it will show everything fine, but it won't insert anything in database. The table name is correct. Code - global $wpdb; $meta2 = ...
1
vote
1answer
3k views

How does $wpdb handle COUNT(*)

I understand how to do simple queries and display results using $wpdb. This is my process: <?php $sql = 'select * from wp_votes;'; ?> <?php $votes = $wpdb->get_results($sql); ?> ...
0
votes
1answer
1k views

Wordpress database error: [Query was empty] - using $wpdb->prepare()

I have edited my question, I'm now getting the error about checking my MySQL settings. I changed the $sql_dvalues variable to an array with the values instead of comma spaced values and now it is ...
0
votes
3answers
5k views

wpdb->prepare and mysql UPDATE - how is it done?

Trying to set a 'removed' date time in a plugin query but I'm not sure how to use UPDATE SET with $wpdb->prepare. Here's my query: $cur_date = date('Y-m-d G:i:s'); $rows_affected = ...
0
votes
1answer
96 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
1answer
397 views

Making plugin to use different table prefix cause permission problem

I have multiple wordpress websites that uses the same files and database but with different table prefixes, I use a plugin "Shortcode Exec PHP" and I would like to use the same shortcodes on all the ...
1
vote
1answer
473 views

MySQL Query To Select Post By Postmeta

I have two custom post types, type1 and type2. Type2 posts have a postmeta called postID that is the ID number of a post in type1. When showing type1 in single.php I want a mysql query that selects ...
4
votes
1answer
235 views

Get total number of comments from posts in a specific custom taxonomy

I’m having some difficulties trying to get total number of comments from posts within a specific custom taxonomy. The setup is as such: I’ve created a custom taxonomy for my posts, called “features”. ...
1
vote
1answer
4k views

$wpdb->insert - inserting multiple rows

How do I use $wpdb->insert to insert multiple rows. Here is my code. for($i=0; $i<=$urlCount; $i++) { $stat = $wpdb->insert( 'WP_URLS', array( 'POSTID' => ...
1
vote
1answer
127 views

MySQL Rank & $wpdb

I need a rank column in my MySQL statement, for example: SET @rank=0; SELECT @rank:=@rank +1 as rank, player, points FROM my_table Is there a way to use the above with $wpdb? WordPress doesn't ...
2
votes
2answers
1k views

Use $wpdb in wordpress theme files

I want to use $wpdb in a theme file, but it doesn't work. My code is bellow: <?php $action = $_POST['action']; $updateRecordsArray = $_POST['recordsArray']; if ($action == "updatelist") { ...
0
votes
2answers
986 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; ...
1
vote
1answer
1k views

$wpdb doesn't appear to work on page inside of a plugin

I have a plugin folder foobar. Inside this plugin I have a page called foobar.php. Inside this page I have global $wpdb; $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : ...
4
votes
1answer
3k views

wpdb->insert: do I need to prepare against SQL injection?

Do I need to use wpdb prepare before wpdb->insert? If I am inserting values into a wordpress table using wpdb->insert, do I need to "clean" my data before inserting it or does this method ...
0
votes
1answer
941 views

AJAX wp-mysql running too slow

I have made a function of ajax, which returns all the posts starting with a particular alphabet, suppose a user clicks on letter A, then all the posts starting with letter A will be displayed, any how ...