Skip to:
Content
Pages
Categories
Search
Top
Bottom

Getting a value from one of the users xprofile fields

  • Avatar of hamdmaan
    hamdmaan
    Participant

    @hamdmaan

    Hi,
    Long time lurker first time poster – i’ve got a bit of a problem that I just can’t figure out;

    I’m trying to get the value of the ‘radius’ field for the displayed user into a piece of PHP code to be used later on, but I keep getting errors;

    Here is the code that i’m using:
    (it’s a function that gets the radius value for the user and returns it:

    function gmw_get_radius($user_id) {
    		global $wpdb;
    
            $info = $wpdb->get_row(
                    $wpdb->prepare(
                            "SELECT * FROM <code>wp_uotu_bp_xprofile_data</code> WHERE user_id = $user_id AND field_id =1255"
            ));
    		
    		return ( isset($info) ) ? $info : false;
    		
    }

    The error that I receive via WP debug is :

    Warning: Missing argument 2 for wpdb::prepare(), called in /home3/housepa7/public_html/wp-content/plugins/geo-my-wp/plugins/friends/includes/gmw-fl-functions.php on line 35 and defined in /home3/housepa7/public_html/wp-includes/wp-db.php on line 1147
    
    Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.) in /home3/housepa7/public_html/wp-includes/functions.php on line 3245
    

    Any help towards this would be very much appreciated and I can provide any more info if needed, thanks!

    NOTE: I just checked the post and it added code tags around some of the php – this is not intended and they should be apostrophes!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    You don’t really need ‘prepare’ for a hard-coded query.

    Your error is due to ‘prepare’ using of sprintf-like approach.
    Read the codex: wpdb

    Why use Select * when you only need ‘value’?
    Why use get_row when you only need a single value? See ‘get_var’ in the link above.

    But why are you making a wpdb call?

    If you’re not in the member loop or on a member page, try
    $radius = xprofile_get_field_data('name-of-radius-field', $user_id);
    Otherwise, try:
    bp_get_member_profile_data('field=name-of-radius-field');

    Avatar of hamdmaan
    hamdmaan
    Participant

    @hamdmaan

    Ah I see – I really didn’t know that the function existed! Thank you very much for your fast response and it is now working perfectly!!!

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.