﻿id,summary,reporter,owner,description,type,status,priority,milestone,component,version,severity,resolution,keywords,cc
14997,Single filter for all WP_Query clauses,scribu,,"From #14349:

Most times, when you have to manipulate the raw SQL request in WP_Query, you need to alter multiple clauses (JOIN, WHERE etc.). 

Currently, you need to register a callback for each of those:

{{{
function fictional_alter_where( $where, $wp_query ) {
    if ( $wp_query->get( 'custom_var' ) ) {
        $where .= "" AND meta_value IN ( 'foo', 'bar' )"";
    }

    return $where;
}
add_filter( 'posts_where', 'fictional_alter_where' );

function fictional_alter_join( $join, $wp_query ) {
    global $wpdb;

    if ( $wp_query->get( 'custom_var' ) ) {
        $join .= "" JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id )"";
    }

    return $join;
}
add_filter( 'posts_where', 'fictional_alter_join' );
}}}

I think we can all agree that this is pretty cumbersome.

Here's how it can look like:

{{{
function fictional_alter_query( $bits, $wp_query ) {
    global $wpdb;

    if ( $wp_query->get( 'custom_var' ) ) {
    	$bits['where'] .= "" AND meta_value IN ( 'foo', 'bar' )"";
        $bits['join']  .= "" JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id )"";
    }

    return $bits;
}
new WP_Query_Manipulation( 'fictional_alter_query' );
}}}

[http://core.trac.wordpress.org/attachment/ticket/14349/wp-query-manipulation.php WP_Query_Manipulation] is a class that leverages the existing hooks, but it has a lot of overhead and isn't 100% reliable.

So, I propose we add this filter in WP_Query.
",enhancement,closed,normal,3.1,Query,,normal,fixed,has-patch,mikeschinkel@…
