Created
November 17, 2022 07:46
-
-
Save wp126/653ca181c1fb66ff3812992aa5792c2c to your computer and use it in GitHub Desktop.
gravity form with wp_user_query
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
if ( !empty( $_GET['branch'] ) ) { | |
add_action( 'pre_user_query', 'add_my_custom_queries' ); | |
} | |
$user_query = new WP_User_Query( $arr ); | |
if ( !empty( $_GET['branch'] ) ) { | |
remove_action( 'pre_user_query', 'add_my_custom_queries' ); | |
} | |
function add_my_custom_queries( $query ) { | |
global $wpdb; | |
//let's add the billing_coutry to our meta fields in our query | |
$query->query_fields .= ', g_entlr_2.meta_value as branchavalue'; | |
/* echo "<pre>"; | |
print_r($_REQUEST); | |
echo "</pre>";*/ | |
//now we add a left join to actually gather the billing country for our users | |
$query->query_from .= " INNER JOIN db_gf_entry_meta as g_entlr_1 ON $wpdb->users.user_login = ". | |
"g_entlr_1.meta_value and g_entlr_1.meta_key = '11' and g_entlr_1.form_id = '11'"; | |
$query->query_from .= " INNER JOIN db_gf_entry_meta as g_entlr_2 ON g_entlr_1.entry_id = ". | |
"g_entlr_2.entry_id and g_entlr_2.meta_key = '10' and g_entlr_2.form_id = '11' and g_entlr_2.meta_value = '".$_GET['branch']."' "; | |
//and the last step is ordering users based on the billing_country values, when present | |
// $query->query_orderby = ' ORDER BY billing_country.meta_value DESC'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment