Skip to content

Instantly share code, notes, and snippets.

@codehooligans
Created June 19, 2012 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codehooligans/2954788 to your computer and use it in GitHub Desktop.
Save codehooligans/2954788 to your computer and use it in GitHub Desktop.
WordPress MarketPress query filter
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