function agp_parse_after_WHERE_11($request, &$pos_where, &$pos_suffix)
{
    $request_u = strtoupper($request);
    $pos_where = strpos($request_u, ' WHERE 1=1');
    if (!$pos_where) {
        if ($pos_suffix = agp_get_suffix_pos($request)) {
            $where = substr($request, $pos_suffix);
        }
    } else {
        // note: this will still also contain any orderby/limit/groupby clauses ( okay since we won't append anything to the end )
        $where = substr($request, $pos_where + strlen(' WHERE 1=1 '));
    }
    return $where;
}
 function flt_terms_request($request, $taxonomies, $args = array())
 {
     //$defaults = array( 'reqd_caps_by_otype' => array(), 'is_term_admin' => false, 'required_operation' => '', 'post_type' => '' );
     // determine term id col (term_id or term_taxonomy_id) for term management queries
     if (strpos($request, 'AS tt')) {
         $args['term_id_col'] = 'tt.term_taxonomy_id';
     } elseif (strpos($request, 'AS t')) {
         $args['term_id_col'] = 't.term_id';
     } else {
         global $wpdb;
         if (strpos($request, $wpdb->terms)) {
             $args['term_id_col'] = "{$wpdb->terms}.term_id";
         } elseif (strpos($request, $wpdb->term_taxonomy)) {
             $args['term_id_col'] = "{$wpdb->term_taxonomy}.term_taxonomy_id";
         }
     }
     if ($rs_where = $this->flt_terms_where('', $taxonomies, $args)) {
         if (strpos($request, ' WHERE ')) {
             $request = str_replace(' WHERE ', " WHERE 1=1 {$rs_where} AND ", $request);
         } elseif ($pos_suffix = agp_get_suffix_pos($request)) {
             $request = substr($request, 0, $pos_suffix) . " WHERE 1=1 {$rs_where} " . substr($request, $pos_suffix);
         } else {
             $request .= " WHERE 1=1 {$rs_where} ";
         }
     }
     //d_echo ("<br /><br />terms_request output:$request<br /><br />");
     return $request;
 }