Skip to content

Instantly share code, notes, and snippets.

@annalinneajohansson
Last active August 29, 2015 13:56
Show Gist options
  • Save annalinneajohansson/99809b98dacf8d2344e9 to your computer and use it in GitHub Desktop.
Save annalinneajohansson/99809b98dacf8d2344e9 to your computer and use it in GitHub Desktop.
SQL SELECT to match a searchterm in wp_terms but only from a specific taxonomy
SELECT * FROM $termstable AS terms
JOIN ".$wpdb->prefix."term_taxonomy AS termtax ON terms.term_id = termtax.term_id
WHERE termtax.taxonomy = '$taxonomy'
AND terms.name LIKE '%$searchterm%' COLLATE utf8_swedish_ci
ORDER BY termtax.count DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment