Created
March 17, 2016 01:10
-
-
Save wvega/451f524f598d344c8d15 to your computer and use it in GitHub Desktop.
Code used to create SQL clauses for meta queries using custom tables (Draft)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$regions_query = new WP_Meta_Query( $query_object->query['_regions_query'] ); | |
$regions_clauses = $regions_query->get_sql( 'post', $this->db->posts, 'ID', $query_object ); | |
$regions_clauses['join'] = str_replace( $this->db->postmeta, AWPCP_TABLE_AD_REGIONS, $regions_clauses['join'] ); | |
$regions_clauses['join'] = preg_replace( "/mt(\d+)/", 'listing_regions\1', $regions_clauses['join'] ); | |
$regions_clauses['join'] = str_replace( 'post_id', 'ad_id', $regions_clauses['join'] ); | |
$regions_clauses['where'] = str_replace( $this->db->postmeta, AWPCP_TABLE_AD_REGIONS, $regions_clauses['where'] ); | |
$regions_clauses['where'] = preg_replace( "/mt(\d+)/", 'listing_regions\1', $regions_clauses['where'] ); | |
$regions_clauses['where'] = preg_replace( | |
"/(\w+).meta_key = '(\w+)' AND CAST\([^)]+\) (LIKE '(?:\\\'|[^'])+')/", | |
'$1.$2 $3', | |
$regions_clauses['where'], | |
-1, | |
$count | |
); | |
$clauses['join'] = $clauses['join'] . $regions_clauses['join']; | |
$clauses['where'] = $clauses['where'] . $regions_clauses['where']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment