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...
LIKE
? I something appended or prepended to_create_new_group
?_create_new_group
and is like the input. Have I got that wrong?get_posts()
is an extremely wasteful way to get this information. That will trigger numerous queries where only one is necessary. Sorry, I usually defend using Core functions, but only when it makes sense. Core really needs a way to pull data of this nature but I am not aware of one.