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

query for filtering published posts?

i need to filter count based on a date and post_status = 'publish', how to write a query to filter, as far as now i have filtered based on date, what is the query need to filter based published post. ...
0
votes
2answers
173 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
793 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
2answers
17k views

How to parse row results from $wpdb -> get_results

I have the following: $query = 'SELECT * FROM wp_pod_tbl_add_questions WHERE id LIKE '. $id; $row = $wpdb -> get_results($query); How do I get the ...
0
votes
1answer
474 views

$post not working working in AJAX plugin with custom post type

I am trying to create a plugin that can relate two posts to each other, and to do so I am trying to use AJAX, but I am having trouble getting the current posts ID using $post->ID. I am trying to ...
0
votes
2answers
1k views

How to change a custom query into a standard loop?

I'm trying to modify how results are displayed in a post list that's currently controlled by the code below. However, it's not built in the WP_Query while ( $the_query->have_posts() ) : ...
6
votes
2answers
284 views

Does wpdb add considerable overhead on queries with large result sets?

I am working on backup-related plugin and from some research of existing plugins - they seem to favor using PHP's mysql_* functions, rather than $wpdb. Is $wpdb overhead considerable enough that it ...
2
votes
3answers
5k views

Pagination with custom SQL query

I have my own SQL string to select Custom Post Type posts with specific WHERE clause. I've used the offset and limit to return appropriate posts depending on a page being displayed. That's working ...
0
votes
1answer
706 views

Wpdb->insert() doesn't insert new row after the last one

In JavaScript, I'm using an Ajax call and I'm sending an array of shops. Except for the last element in the array all the shops already exist in the DB. The last element is a new shop. The PHP code ...
0
votes
1answer
2k views

Join inside a wpdb query.. confused!

I need to get a return from a query that provides me with email, username or nicename as well as post title based on author id. The query is to run once daily via cron and look for posts that have ...
3
votes
2answers
1k views

Does $wpdb->prepare not create a prepared statement that I can execute multiple times?

I am wondering from the syntax $sql = $wpdb->prepare( 'query' [, value_parameter, value_parameter ... ] ) It appears (from the syntax - values within prepare) that it simple escapes values not ...
1
vote
2answers
241 views

How do I order my loop query?

I have a table in my database containing vote a tally I'm trying to order posts by. screenshot: the table I've tried something like this, which brings up all the voted posts and pagination okay but ...
0
votes
1answer
94 views

db query for retrieving comments without any reply

what is a query for selecting a list of comment id's that have not had a reply yet so I can use it to iterate though each comment id and echo out the post it is on and the excerpt of the comment along ...
0
votes
1answer
125 views

How to create a list of terms who's posts also have a predefined external term?

I have a pretty extensive music collection and my friends are always borrowing my stuff. I would like to keep better track of my library so I'm building a sudo-checkout system using WP. The ...
0
votes
1answer
575 views

Out of Memory - Line 791 of WP-DB.php (mysql_real_escape_string)

Update The end result is that I did not account for Apache memory limits. There were limits placed on the Apache process which caused PHP to be limited regardless of the settings placed on it. ...
2
votes
1answer
922 views

How to filter a dd/mm/yyyy date from a custom field in a query

I'm trying to build a query in order to sort some posts by a date custom field, where the dates are formatted dd/mm/yyyy. It works by querying the database directly with get_results like in this ...
1
vote
1answer
174 views

Most effective use of DB querys

I've got a custom database table with lots of data that I'd like to query several times from a custom template file I've built. Say the db table looks like this: id name city zip 23 ...
2
votes
1answer
2k views

Can't use get_results() in ajax query

I'm using a jquery ajax call to get certain data from wpdb and I'm getting the following message: <b>Fatal error</b>: Call to a member function get_results() on a non-object in ...
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
2answers
1k views

How to test the outcome of a wpdb query?

I want to get all the data with the meta key of "project_id" from post meta table. I wrote a query, it should work in thoery, but I have no way to see what I get, and inject this query to my plugin ...
-1
votes
1answer
296 views

How to get all the related ids without array?

I want to get all the post ids when the post meta includes a key of "project_id". This function get the job down, but need refine: function get_all_ids(){ global $wpdb, $post; $meta_key1 = ...
2
votes
1answer
373 views

get posts and postmetas in assoc array

how do I get all posts and postmetas in an associative array? $allposts = $wpdb->get_results(" SELECT $wpdb->posts.post_title, $wpdb->postmeta.meta_key FROM $wpdb->posts JOIN ...
3
votes
1answer
6k views

Should I use wpdb prepare?

I'm new to SQL and am wondering if I need to use wpdb->prepare for the following query to a table I've created global $wpdb; $tablename = $wpdb->prefix . "my_custom_table"; $sql = "SELECT * ...
1
vote
2answers
761 views

Call External Object in Class Function During Callback

I've a class which has a function that check and creates table in database. In order to do so i need to use WordPress $wpdb object. I need the function to run only on first plugin activation, so i ...
7
votes
5answers
9k views

Showing errors with $wpdb update

I am using $wpdb->update to update a custom table I have in my database. When I var_dump the result it returns: int(0) So I tried $wpdb->print_error() to see what's wrong. However, it shows ...
2
votes
1answer
432 views

How to add/change a value of $wpdb property/var?

There is a problem: I want to add a table 'linkmeta' to work like 'postmeta' or 'commentmeta'.. and use functions like add_metadata / update_metadata / delete_metadata! but, in this functions call ...
1
vote
1answer
441 views

Return XML of Post Metadata

All of my posts in one category (i.e. Location) have two custom fields: latitude and longitude. I would like to return an XML or JSON of all those posts (title, latitude, longitude) for use as Google ...
3
votes
1answer
2k views

$wpdb->query() multiple query support

Just bump into the issue that I can't execute multiple sql queries using the $wpdb->query(). Generated queries work fine directly in phpmyadmin so its something will the ezSQL class only. By design ...
2
votes
1answer
265 views

Querying Email Addresses for a List of Users with Same Last Name?

I have a site with many users and many of them have the same last name. I want to get the emails of all the users with the same last name (IE: Smith) that has a post related to a particular taxonomy ...
3
votes
3answers
681 views

LEFT JOIN, INNER OUTER JOIN, LEFT OUTER JOIN is driving me crazy. Please help?

fellow coders! I an having a hard time JOIN(ing) tables. I have a a lot of users on my site and many of them have the same last names. I am trying to get their emails by their last name. WP stores ...
6
votes
3answers
27k views

$wpdb->get_row() only returns a single row?

Why is it? I tried the same query in the console and it returned multiple rows. Here's the query: $this->wpdb->get_row("SELECT * FROM ".$this->wpdb->users." WHERE status = 'active'", ...
3
votes
1answer
181 views

How to make an activities stream mixing posts and comments?

What I'm currently trying to make is an activities stream wich list : The posts, the comments, both mixed between them and ordered by date. My idea is to make two queries, but i don't know how to ...
0
votes
2answers
2k views

Use mysql_query instead of $wpdb query

I have a custom table inside my wordpress database called test. What if i query this table using mysql_query() instead of using for example $wpdb->get_results() Will this affect my performance? Ty ...
0
votes
1answer
208 views

Compare transient data with a meta box value

So I'm not sure what would be the best way to go about this in terms of best practices and optimization. Scenario: I have query that parses an external XML feed and stores the data using the ...
1
vote
2answers
2k views

mysql query two database tables, users and usermeta and sort by custom meta int value

I am trying to get an array of site users sorted by a custom meta value (an int). I can query the users just fine and get them back to use in a foreach. I currently have the query results come back ...
2
votes
2answers
663 views

Creating a Post form outside of the Admin

I am merging Wordpress into a existing system and require our users to be able to make posts to a multi-site WP install. I have a database table that will link our own member to specific blog IDs and ...
1
vote
4answers
3k views

Export wordpress table to excel

I have created PHP scripts before to export a database table to .xls format like this: $select = "SELECT * FROM tracking"; $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) ...
2
votes
3answers
764 views

Using $wpdb object in a widget

I'm trying to make a very simple widget that access tables contained within the same database instance as my Wordpress database, but are not wordpress tables. I'm using the wpdb class according to the ...
4
votes
3answers
6k views

How do you properly prepare a %LIKE% SQL statement?

I'd like to use a LIKE %text% statement while still using the WordPress $wpdb class to sanitize and prepare input. SELECT column_1 from `prefix_my_table` WHERE column_2 LIKE '%something%'; I've ...
0
votes
2answers
678 views

Have working sql query… trying to adjust it to use $wpdb

So I have this code that queries a custom plugin generated table in the wp database. It works perfectly as is. But I'm trying to adjust it to use $wpdb instead of the $con function I have set up. ...
2
votes
3answers
1k views

Does a query executed through wpdb class get cached?

I am not sure how WordPress cache the queries. I had the impression that whenever I execute a query through wpdb class, it gets cached. For example, on codex under Select a Row and Select a Var, it ...
0
votes
1answer
370 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: ...
1
vote
1answer
2k views

How to close wpdb connection?

Is there any method to close connection similar to mysql_close() for wpdb in wordpress? Is it not necessary to close connection for global wpdb?
1
vote
1answer
278 views

In what part of the Wordpress core does the users table and usermeta table get joined?

I have been trying to work out just where in the massive jungle of Wordpress include classes the usermeta table is joined onto the users table and if so, how does it work? The one confusing thing ...
0
votes
1answer
764 views

Ajax future single post query doesn't work when NOT logged in

I am having a problem with an ajax request for a single post, when the user is not logged in. The post is a calendar date and is in the future. the query works fine if I am logged into wordpress but ...
3
votes
2answers
973 views

$wpdb->insert is changing a value

I'm writing a plugin called 'Featured Releases' for a client. The user fills out a short form in the admin area which inserts some text and an image id into the wordpress database via $wpdb->insert. ...
0
votes
1answer
271 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, ...
2
votes
1answer
4k views

Check for success of $wpdb->update() correctly

My code is if( $wpdb->update($tableName,array('opt_value'=>$cInfo),array('opt_name'=>'showWeatherWidget'))) //show success message else // show failure message This is not ...
3
votes
1answer
1k views

what are the differences between wp_users and wp_usermeta tables?

what are the differences between wp_users and wp_usermeta tables? i use wp-email-login plugin and i just noticed that if a user change his email in the profile page it saved in the wp_usermeta table ...
1
vote
1answer
2k views

Safe way to find last inserted id in a table?

Is it safe to use $wpdb->insert_id; to find the id of a last updated row id just after an update? ex: $sql = $wpdb->insert($table_name, $arrayWithDataToInsert, array('%s','%s')); ...