WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$s = $_POST['submitterms'];
$querystr = "
            SELECT $wpdb->terms.*
            FROM $wpdb->terms
            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>';

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:

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

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

share|improve this question
up vote 0 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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