Similar to how you can insert into an array using code such as

$wpdb->insert( $table_name, $inputs); //where inputs is an array

I want to do a sql select statement with code such as

$wpdb->get_results("SELECT * FROM " . $table_name . " WHERE " . $input);

where input could contain several search parameters. Is anything like this possible?

  • "Is anything like this possible" won't really bring up the best answers. Better would be to rethink your question and file an edit.
    – kaiser
    Jan 27, 2014 at 17:25

1 Answer 1


Pass your information through prepare as in this example from the Codex:

$metakey = "Harriet's Adages";
$metavalue = "WordPress' database interface is like Sunday Morning: Easy.";

$wpdb->query( $wpdb->prepare( 
        INSERT INTO $wpdb->postmeta
        ( post_id, meta_key, meta_value )
        VALUES ( %d, %s, %s )
) );

Your array should have the same number of elements as your query string has placeholders.

  • 1
    The question is asking about select. Jan 23, 2015 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.