I need to get 10 current user fields and pass the field values to a post string. The post string is expecting certain label names for each value.
Example - post string expects 'firstname' => 'value', not 'user_firstname' => 'value'. After days of fatal parse errors for syntax, now I just get a fail status. Either my array code or post code, (or both), is somehow flawed. I read a post today from 2011 that says since WordPress 3.3 (current version now is 3.9), that the way custom user fields are called is different. The post > http://scribu.net/wordpress/the-magic-of-wp_user.html says the way to call custom WP fields like 5 of mine are, is like this:
if ( $current_user->has_prop( 'my-field' ) ) )
echo '<p>
' . $current_user->get( 'my-field' ) . '
</p>';`
So this is the code I have right now:
//Get values for these 10 user fields
function wp_get_current_user() {
$current_user = wp_get_current_user();
$current_user_info = array(
'firstname' . $current_user->user_firstname =>' ',
'lastname' . $current_user->user_lastname =>' ',
if ( $current_user->has_prop( 'mepr-address-one' ) ) )
' . $current_user->get( 'mepr-address-one' ) . => ' ',
if ( $current_user->has_prop( 'mepr-address-city' ) ) )
' . $current_user->get( 'mepr-address-city' ) . => ' ',
if ( $current_user->has_prop( 'mepr-address-state' ) ) )
' . $current_user->get( 'mepr-address-state' ) . => ' ',
if ( $current_user->has_prop( 'mepr-address-zip' ) ) )
' . $current_user->get( 'mepr-address-zip' ) . => ' ',
if ( $current_user->has_prop( 'mepr-address-country' ) ) )
' . $current_user->get( 'mepr-address-country' ) . => ' ',
'email' . $current_user->user_email =>' ',
'username' . $current_user->user_login =>' ',
'password' . $current_user->user_pass =>' '
);
}
// Generate the POST string
// These last three lines aren't posting my get user values
$postdata = '';
foreach($query_vals as $key => $value){
$postdata .= $key.'='.urlencode($n=$value).'&';
}
And the post string needs to meet the parameters described in the post that is this:
foreach ( get_user_meta( $user->ID ) as $key => $values ) {
var_dump( $key, $values );
}
But being a php newb, I'm not sure of the coding syntax. Don't I have to define has_prop before I can use it?
Functionshould befunction