PriMoThemes — now s2Member® (official notice)
This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™
<?php $fields = json_decode(S2MEMBER_CURRENT_USER_FIELDS, true); ?>
<?php echo $fields["first_name"]; ?> <?php echo $fields["last_name"]; ?>
<?php print_r(json_decode(S2MEMBER_CURRENT_USER_FIELDS, true)); ?>
//getting the info form the system
$query = "SELECT meta_value FROM wp_usermeta WHERE user_id='3' && meta_key='wp_s2member_custom_fields'";
$resultx = @mysql_query ($query);
$rowx = mysql_fetch_array ($resultx, MYSQL_NUM);
if(mysql_num_rows($resultx) != 0) {
$not = $rowx[0];
$custom_field_array = explode('"', $not);
// array [1] is the field name, array [3] is the value
echo "field name: " . $custom_field_array[1] . "<br/>";
echo "field value: " . $custom_field_array[3];
}
$query = $wpdb->get_col( $wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users " ));
$totalrows = count($query);
//getting the info form the system
//create the query to the database
$query = "SELECT meta_value FROM wp_usermeta WHERE user_id='3' && meta_key='wp_s2member_custom_fields'";
/*
## deprecated in favor of default wordpress query
##
## $resultx = @mysql_query ($query);
## $rowx = mysql_fetch_array ($resultx, MYSQL_NUM);
## if(mysql_num_rows($resultx) != 0) {
## $not = $rowx[0];
*/
$resultx = $wpdb->get_col($query); //set the results to a usable variable
/*
## Seperate the variable into an array of strings
## using the quotation mark " as the seperator
*/
$custom_field_array = explode('"', $resultx[0]);
/*
## to avoid the data we don't want we need to skip every second number
## array [1] is the field name, array [3] is the value
## using the 1 and 3 logic, the next field/value pair will be [5] and [7],
## then [9] and [11] etc
*/
echo "field name: " . $custom_field_array[5] . "<br/>";
echo "field value: " . $custom_field_array[7];
$UserData = 3;//UserID; to be set as a counter on a later loop edit
//getting the info form the system
//create the query to the database
$query = "SELECT meta_value FROM wp_usermeta WHERE user_id='$UserData' && meta_key='wp_s2member_custom_fields'";
/*
## deprecated in favor of default wordpress query
##
## $resultx = @mysql_query ($query);
## $rowx = mysql_fetch_array ($resultx, MYSQL_NUM);
## if(mysql_num_rows($resultx) != 0) {
## $not = $rowx[0];
*/
$resultx = $wpdb->get_col($query); //set the results to a usable variable
/*
## Seperate the variable into an array of strings
## using the quotation mark " as the seperator
*/
$custom_field_array = explode('"', $resultx[0]);
/*
## to avoid the data we don't want we need to skip every second number
## array [1] is the field name, array [3] is the value
## using the 1 and 3 logic, the next field/value pair will be [5] and [7],
## then [9] and [11] etc
*/
$FieldData[$custom_field_array[1]] = $custom_field_array[3]; //set first array field and value
$Remaining_array_count = count($custom_field_array) -4; //offset count to compensate for first value set
//iterate through the array to retrieve the remaining key/value pairs and insert them to the new array
for($i=3;$i<$Remaining_array_count;$i){
$FieldData[$custom_field_array[$i+2]] = $custom_field_array[$i+4];
$i = $i+2;
}
//set the resulting array into a multidimensional array using UserData
//to 'index' custom fields and contain them per user
$Fields_By_User = array
(
$UserData => $FieldData
);
//print the array to test results
print_r($Fields_By_User);
//print the count being iterated on original array
echo "<br/>".$Remaining_array_count;
$UserData = 3;//UserID; to be set as a counter on a later loop edit
//create the query to the database
$query = "SELECT meta_value FROM wp_usermeta WHERE user_id='$UserData' && meta_key='wp_s2member_custom_fields'";
$results = $wpdb->get_col($query); //set the results to a usable variable
/*
## create an array to holdand unserialize the string,
## which places it into a key=>value pair with 'key' being
## the field name and 'value' being the value of the field
*/
$field_value_pairs = unserialize ($results[0]);
/*
# create a multidimensional array to connect all of
# the field=>value pairs to the user
*/
$Fields_By_User = array
(
$UserData => $field_value_pairs
);
/*
# To access the array you need to use the the keys of the
# user [$UserData] and the field names ['samplefield1']
# so if you had a field with the name 'city' you would get
# it's value buy typing $Fields_By_User[$UserData]['city'];
*/
echo $Fields_By_User[$UserData]['samplefield1'];
$user_query = $wpdb->get_col( $wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users " ));
$UserData = count($user_query);
$Fields_By_User = array(
for($i=0;$i<$UserData;$i++)
{
$query = "SELECT meta_value FROM wp_usermeta WHERE user_id='$i' && meta_key='wp_s2member_custom_fields'";
$results = $wpdb->get_col($query);
$field_value_pairs = unserialize ($results[0]);
$i => $field_value_pairs
} );
//////////////////////////////
// Match criteria //
//////////////////////////////
$field_name = "samplefield1";
$Match_1 = "";
$Match_2 = "";
//////////////////////////////
$user_query = $wpdb->get_col( $wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users " ));
$UserData = count($user_query); //UserID; to be set as a counter on a later loop edit
for($t=0;$t<$UserData;$t++){
//create the query to the database
$query = "SELECT meta_value FROM wp_usermeta WHERE user_id='$t' && meta_key='wp_s2member_custom_fields'";
$results = $wpdb->get_col($query); //set the results to a usable variable
/*
## create an array to holdand unserialize the string,
## which places it into a key=>value pair with 'key' being
## the field name and 'value' being the value of the field
*/
$field_value_pairs = unserialize ($results[0]);
/*
# create a multidimensional array to connect all of
# the field=>value pairs to the user
*/
if($field_value_pairs[$field_name] == Match_1)
{
//if match is found, add it to the array
$Fields_By_User[$t] = $field_value_pairs;
}
/* sample to match 2 fields
if($field_value_pairs[$field_name] == Match_1 && $field_value_pairs[$field_name] == Match_2)
{$Fields_By_User[$i] = $field_value_pairs;}
*/
}//end for loop
/*
# To access the array you need to use the the keys of the
# user [$UserData] and the field names ['samplefield1']
# so if you had a field with the name 'city' you would get
# it's value buy typing $Fields_By_User[$UserData]['city'];
*/
//echo $Fields_By_User[$UserData]['samplefield1'];
echo "<br/>";
print_r($Fields_By_User);
//////////////////////////////
// Match criteria //
//////////////////////////////
$field_name = "samplefield1";
$Match_1 = "somethign to write here";
$Match_2 = "";
//////////////////////////////
$user_query = $wpdb->get_col( $wpdb->prepare("SELECT $wpdb->users.ID FROM $wpdb->users " ));
$UserData = count($user_query); //UserID; to be set as a counter on a later loop edit
for($t=1;$t<=$UserData;$t++){
//create the query to the database
$query = "SELECT meta_value FROM wp_usermeta WHERE user_id='".$t."' && meta_key='wp_s2member_custom_fields'";
$results = $wpdb->get_col($query); //set the results to a usable variable
/*
## create an array to holdand unserialize the string,
## which places it into a key=>value pair with 'key' being
## the field name and 'value' being the value of the field
*/
$field_value_pairs = unserialize ($results[0]);
/*
# create a multidimensional array to connect all of
# the field=>value pairs to the user
*/
if(!empty($field_value_pairs)){
//if($field_value_pairs[$field_name] = Match_1)
if(in_array($Match_1,$field_value_pairs, TRUE))
{
//if match is found, add it to the array
$Fields_By_User[$t] = $field_value_pairs;
}
}
}//end for loop
/*
# To access the array you need to use the the keys of the
# user [$UserData] and the field names ['samplefield1']
# so if you had a field with the name 'city' you would get
# it's value buy typing $Fields_By_User[$UserData]['city'];
*/
//echo $Fields_By_User[$UserData]['samplefield1'];
echo "<br/>";
print_r($Fields_By_User);
echo "<br/>";
$person = get_userdata( ID );
echo $person->wp_s2member_custom_fields["custom_field_key"];
$nwfa_members = get_users();
foreach ($nwfa_members as $user) {
$s2_data = get_userdata($user->ID);
echo $user->display_name . ' - City: ' . $s2_data->wp_s2member_custom_fields["s2_city"];
}
Users browsing this forum: Yahoo [Bot] and 2 guests