Preferred Method of debugging a wordpress SQL calls?

Turn on define( ‘WP_DEBUG’, true ); and define( ‘SAVEQUERIES’, true ); . I prefer the format of the debug bar, http://wordpress.org/extend/plugins/debug-bar/ , which can be combined with the console, http://wordpress.org/extend/plugins/debug-bar-console/ . This script is great for profiling, Best Collection of Code for your functions.php file There are some other plugins that might help, like Debug … Read more

Modify the structure of data returned by $wpdb

You can do this one of two ways, as far as I can see: Use PHP to combine the current results to the one you want. Basically: $records = array(); foreach( $results as $result ) { $record_id = $result[‘item_id’]; if (empty($records[$record_id])) { $records[$record_id][‘item_id’] = $result[‘item_id’]; $records[$record_id][‘item_name’] = $result[‘item_name’]; $records[$record_id][‘sub_items’] = array(); } $records[$record_id][‘sub_items’][] = array( … Read more

Fetch all Posts where logged in user has commented

It should be simple since comments are stored with a user_id if they are created by a logged in user and if not then its set to false so all you need to do is select the post id from comments that are made by user_id bigger the zero, something like this: function get_posts_with_loogedin_user_comments(){ global … Read more

posts_where Fails with More than One Custom Field in Query

Think about your query. You are asking that $wpdb->postmeta.meta_key be both “foo” and “bar”. That will never happen. If you ran this in a context where you’d get to read MySQL debugging data (PhpMyAdmin’s SQL console will do this) you would probably see a warning about an “impossible where clause”. You need to JOIN on … Read more

$wpdb select date range of posts

You basically have the answer, just add $date2 to the inner sql where clause: AND p.post_date > ‘$date2’ to get last week. To get a particular week, use AND p.post_date < ‘$date1’ AND p.post_date > ‘$date2’ where eg $date1 = date(‘Y-m-d’, strtotime(‘2014-07-04 +1 days’)); $date2 = date(‘Y-m-d’, strtotime(‘2014-07-04 -8 days’)); To return weekly/total votes, you … Read more

What’s wrong with my $wpdb prepare?

These look like 2 separate questions. The first I think is a single vs double quotes issue: Try this: $html=””; foreach ( $recent_across_network as $post ) { $html .= ‘blog_id, ‘.$post->ID.’ ) . ‘”>’ . $post->post_title . ”; } $html .= ”; The line in the foreach is putting $post->ID in single quotes which won’t … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)