Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
$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?

share|improve this question

1 Answer 1

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

 
discard

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.