Quantcast
Channel: Question and Answer » wpdb
Viewing all articles
Browse latest Browse all 44

Custom Query – Based on user input

$
0
0

I’m working on displaying suggestions to an input, assisting the user.

I’m using the included jQuery suggest. That’s loading – and through ajax I’m using a custom SQL query and can see it’s attempting to pull it in.

I’m having trouble writing the SQL query.

Here’s what I have so far.

global $wpdb;

// group name key
$meta_key = '_create_new_group';
// user input
$search = $_REQUEST['q'];

$groupnames = $wpdb->get_col($wpdb->prepare(
    "
    SELECT  meta_value 
    FROM    $wpdb->postmeta
    WHERE   meta_key = %s
    LIKE    %s // Works up to here
    ",
    $meta_key,
    $search
));

To get to where I am now I’ve used examples from the wpdb class reference. http://codex.wordpress.org/Class_Reference/wpdb

When I type into the input, the query overloads the server. And a var_dump as far as it’ll load starts to list meta values outside of what I’m querying (as far as I can see).

Can anyone see where I must be clearly going wrong…


Viewing all articles
Browse latest Browse all 44

Trending Articles