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 '14 at 17:25

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. – Andrew Welch Jan 23 '15 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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