WordPress.org

Ready to get started?Download WordPress

Forums

get_results() stripping out numbers from query when IN() is used (1 post)

  1. madsem
    Member
    Posted 2 years ago #

    I am wondering why the get_results() function is stripping out anything between the brackets when I include IN() in my query.

    For example:

    $query = "SELECT * FROM test WHERE id= 1 AND something IN (45,67,55)";

    When I run get_results($query); I am given a MYSQL error with the numbers completely removed, leaving the query looking like this:

    "SELECT * FROM test WHERE id = 1 AND something IN()

    Precisely, I am seeing this problem with the Buddypress followers plugin, on the newest version of Buddypress and newest version of WordPress. When I test the query manually it works, but on the site it strips out the numbers for no obvious reason

    Here is the code in question:

    function bulk_check_follow_status( $leader_ids, $user_id = false ) {
    		global $bp, $wpdb;
    
    		if ( empty( $user_id ) )
    			$user_id = $bp->loggedin_user->id;
    
    		$leader_ids = $wpdb->escape( implode( ',', (array)$leader_ids ) );
    
    		return $wpdb->get_results( $wpdb->prepare( "SELECT leader_id, id FROM {$bp->follow->table_name} WHERE follower_id = %d AND leader_id IN ($leader_ids)", $user_id ) );
    	}

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.