0
$s = $_POST['submitterms'];
$querystr = "
            SELECT $wpdb->terms.*
            FROM $wpdb->terms
            WHERE
            lower($wpdb->terms.name) like '%$s%'
         ";
$pageposts = $wpdb->get_results($querystr, OBJECT);
echo '<ul>';
$x = 0;
while ($pageposts[$x]) {
  $post = $pageposts[$x];
  echo '<li>';
  echo '<a href="' . $post->term_id . '">' . $post->name . '</a>';
  echo '</li>';
  $x++;
}

echo '</ul>';

I'm able to get term names that contains the characters i typed into the text box.

But what i want to do is changing term_id AS id AND name AS value so that i can pass the variables like:

$post->id
$post->value
//i.e
echo '<a href="'.$post->id.'">'.$post->value.'</a>';

I guess i need to change the MySQL code. What should I do?

1 Answer 1

0

You can do it easily. Your query should be:

$querystr = "SELECT `term_id` AS `id`, `name` AS `value`, `slug`, `term_group` FROM {$wpdb->terms} WHERE lower($wpdb->terms.name) like '%$s%'";

See, here i've mentioned the name of the fields needed. For any other fields, you need to explicitly mention the field names.

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.