Created
June 19, 2012 15:26
-
-
Save codehooligans/2954788 to your computer and use it in GitHub Desktop.
WordPress MarketPress query filter
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
add_filter( 'query', 'mp_query_filter'); | |
function mp_query_filter($query) { | |
global $wpdb; | |
if ( preg_match( '/('. $wpdb->base_prefix .'mp_terms|'. $wpdb->base_prefix .'mp_term_relationships)/i', $query ) ) { | |
$query_after = str_replace($wpdb->base_prefix."mp_terms", $wpdb->base_prefix."terms", $query); | |
$query_after = str_replace($wpdb->base_prefix."mp_term_relationships", $wpdb->base_prefix."mp_term_relationships", $query_after); | |
// DEBUG START - This following is just for debug to check the output. This will write | |
//the before and after version to a file in your site root | |
$fp = fopen($_SERVER['DOCUMENT_ROOT'] .'/mp_query_log.sql', 'a'); | |
fwrite($fp, "BEFORE: ". $query ."\r\n"); | |
fwrite($fp, "AFTER: ". $query_after ."\r\n"); | |
fwrite($fp, "\r\n"); | |
fclose($fp); | |
// DEBUG END | |
// Set the query to our converted query | |
$query = $query_after; | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment