Skip to content

Commit

Permalink
Bugfix: On sub sites the table prefix gets changed to .= '_' . ->id
Browse files Browse the repository at this point in the history
  • Loading branch information
doctordesh committed Jan 9, 2015
1 parent 606f7b4 commit 8a62448
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Queryer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function getMetaFor(array $posts) {
}

private function sql($ids) {
global $wpdb, $table_prefix;
global $wpdb;

if(!$ids) {
return [];
Expand All @@ -33,11 +33,11 @@ private function sql($ids) {
" . $wpdb->prefix . "postmeta.meta_key,
" . $wpdb->prefix . "postmeta.meta_value,
" . $wpdb->prefix . "mf_post_meta.group_count,
" . $table_prefix . "mf_custom_fields.duplicated as field_duplicated,
" . $table_prefix . "mf_custom_fields.type as field_type,
" . $table_prefix . "mf_custom_fields.options as options,
" . $table_prefix . "mf_custom_groups.name as group_name,
" . $table_prefix . "mf_custom_groups.duplicated as group_duplicated
" . $wpdb->base_prefix . "mf_custom_fields.duplicated as field_duplicated,
" . $wpdb->base_prefix . "mf_custom_fields.type as field_type,
" . $wpdb->base_prefix . "mf_custom_fields.options as options,
" . $wpdb->base_prefix . "mf_custom_groups.name as group_name,
" . $wpdb->base_prefix . "mf_custom_groups.duplicated as group_duplicated
FROM
" . $wpdb->prefix . "posts
LEFT JOIN
Expand All @@ -49,23 +49,23 @@ private function sql($ids) {
ON
" . $wpdb->prefix . "postmeta.meta_id = " . $wpdb->prefix . "mf_post_meta.meta_id
LEFT JOIN
" . $table_prefix . "mf_custom_fields
" . $wpdb->base_prefix . "mf_custom_fields
ON
" . $wpdb->prefix . "postmeta.meta_key = " . $table_prefix . "mf_custom_fields.name
" . $wpdb->prefix . "postmeta.meta_key = " . $wpdb->base_prefix . "mf_custom_fields.name
LEFT JOIN
" . $table_prefix . "mf_custom_groups
" . $wpdb->base_prefix . "mf_custom_groups
ON
" . $table_prefix . "mf_custom_fields.custom_group_id = " . $table_prefix . "mf_custom_groups.id
" . $wpdb->base_prefix . "mf_custom_fields.custom_group_id = " . $wpdb->base_prefix . "mf_custom_groups.id
WHERE
" . $wpdb->prefix . "posts.post_status = 'publish'
AND
" . $wpdb->prefix . "posts.ID IN (" . implode(', ', $ids) . ")
AND
" . $table_prefix . "mf_custom_groups.post_type = " . $wpdb->prefix . "posts.post_type
" . $wpdb->base_prefix . "mf_custom_groups.post_type = " . $wpdb->prefix . "posts.post_type
AND
" . $table_prefix . "mf_custom_fields.post_type = " . $wpdb->prefix . "posts.post_type
" . $wpdb->base_prefix . "mf_custom_fields.post_type = " . $wpdb->prefix . "posts.post_type
AND
" . $table_prefix . "mf_custom_groups.name != 'NULL'
" . $wpdb->base_prefix . "mf_custom_groups.name != 'NULL'
AND
" . $wpdb->prefix . "mf_post_meta.group_count != 'NULL'
GROUP BY
Expand Down
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function __construct($values) {
class WPDB
{
public $prefix = 'wp_';
public $base_prefix = 'wp_';
public static $counter = 0;
public function __construct() {
register_shutdown_function(function() {
Expand Down

0 comments on commit 8a62448

Please sign in to comment.