wp-content/db.php : where is this file?

You would create your own dp.php file in the wp-content directory; if you define $wpdb in there, it will replace WordPress’s default $wpdb object. It’s not listed on the Pluggable Functions list (not a big surprise, as $wpdb is a class, not a function), but it seems similar in concept. Also, if you haven’t read … Read more

wpdb Custom Meta Data with 2 conditions

I found my error in the above query. There still may be a better way to do this, thank you kaiser, and I will update once I’ve done more study. What I forgot to do was GROUP_CONCAT another meta_value so i could pull out different bits. It still seems longer than it needs to be, … Read more

Get data from database table by post_id to get data from second database table

There are a couple things you need to do differently to make this work well. Make sure you’re setting $wpdb to the global. Use $wpdb->prefix instead of hard-coding wp_. Wrap your variables in curly braces. Use $wpdb variables instead of table names, like $wpdb->comments. Always always always use $wpdb->prepare() before performing a query. Using $wpdb->prepare() … Read more

Why does dbDelta() not catch MysqlErrors?

As @Charleston Software Associates mentioned, the DESCRIBE query should not be executed if the table doesn’t exist. The best solution, as he pointed out, is to prevent the error from occurring in the first place. To do so, patch wp-admin/includes/upgrade.php as follows: Change the following line from dbDelta(): $tablefields = $wpdb->get_results(“DESCRIBE {$table};”); to: //Begin core … Read more

Get terms of posts with category with sql

Here’s the solution: global $wpdb; $wpdb->get_results( $wpdb->prepare( “SELECT tags.*, COUNT(tags_rel.object_id) as posts_count FROM {$wpdb->prefix}terms tags INNER JOIN {$wpdb->prefix}term_taxonomy tags_tax ON (tags_tax.term_id = tags.term_id) INNER JOIN {$wpdb->prefix}term_relationships tags_rel ON (tags_tax.term_taxonomy_id = tags_rel.term_taxonomy_id) INNER JOIN {$wpdb->prefix}posts posts ON (tags_rel.object_id = posts.ID) INNER JOIN {$wpdb->prefix}term_relationships cats_rel ON (posts.ID = cats_rel.object_id) INNER JOIN {$wpdb->prefix}term_taxonomy cats_tax ON (cats_rel.term_taxonomy_id = cats_tax.term_taxonomy_id) … Read more

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

Please take a look at the Codex to see how to prepare your statement: // Example straight copy-paste from Codex $metakey = “Harriet’s Adages”; $metavalue = “WordPress’ database interface is like Sunday Morning: Easy.”; $wpdb->query( $wpdb->prepare( ” INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s ) “, 10, $metakey, $metavalue … Read more

Search multiple meta keys at once

You’ll want to use the ‘meta_query’ argument of WP_Query ( http://codex.wordpress.org/Class_Reference/WP_Query ) Here’s a snippet that uses two separate meta key comparisons: $query_args = array( ‘post_type’ => ‘event’, ‘order’ => ‘ASC’, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘_start_date’, ‘meta_query’ => array ( array( ‘key’ => ‘_start_date’, ‘value’ => $_start_of_month, ‘compare’ => ‘>’, ), array( ‘key’ => … Read more

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