• Resolved user70

    (@user70)


    Probably a general coding issue and not specific to the plugin.
    I have the following snippet, but for some reason user_id = $current_user_id is ot working. If I use a known ID for user_id it works correctly.
    I’m still very green, can anyone kindly point out what I’m doing wrong?

    
    function fetch_member_id(){
    	$current_user = wp_get_current_user();
    	$current_user_id = $current_user->ID;
    	global $wpdb;
    	$result = $wpdb->get_results('SELECT meta_value FROM usermeta WHERE meta_key = \'random_number\' AND user_id = $current_user_id');
    	foreach($result as $row){
    		return 'Membership ID: '. $row->meta_value;		
    	}
    }
    
    • This topic was modified 4 years, 9 months ago by user70.
Viewing 1 replies (of 1 total)
  • Thread Starter user70

    (@user70)

    Never mind, this fixed it:

    
    function fetch_member_id(){
    	$current_user = wp_get_current_user();
    	$current_user_id = $current_user->ID;
    	global $wpdb;
    	$result = $wpdb->get_results('SELECT meta_value FROM usermeta WHERE meta_key = \'random_number\' AND user_id = ' . $current_user->ID);
    	foreach($result as $row){
    		return 'Membership ID: '. $row->meta_value;		
    	}
    }
    
    • This reply was modified 4 years, 9 months ago by user70.
Viewing 1 replies (of 1 total)
  • The topic ‘PHP variable in SQL select issues’ is closed to new replies.