• Resolved David Gard

    (@duck_boy)


    Hey all,

    I have a query (below) that is behaving a little odd – Basically, if I echo $query and copy the result to PHPMyAdmin it works fine and I get the desired results, but in WordPress the result is nothing. Any body spot any mistakes at all?

    Thanks.

    $query = "
    	SELECT *
    	FROM $wpdb->posts
    	LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )
    	WHERE $wpdb->postmeta.meta_value LIKE '".$_GET['staff_search']."%'
    	AND $wpdb->postmeta.meta_key = 'staff_surname'
    	AND $wpdb->posts.post_status = 'publish';
    	";
    $staff = $wpdb->get_results($wpdb->prepare($query));
Viewing 1 replies (of 1 total)
  • Thread Starter David Gard

    (@duck_boy)

    Please ignore, I spotted my mistake – it appears that you cannot use $wpdb->prepare() if you are using ‘LIKE’ in the query.

Viewing 1 replies (of 1 total)
  • The topic ‘`$wpdb->get_results` reacting oddly’ is closed to new replies.