Skip to content

Instantly share code, notes, and snippets.

@naotone
Created December 3, 2014 15:28
Show Gist options
  • Save naotone/f15d7eb47168e4e51cb5 to your computer and use it in GitHub Desktop.
Save naotone/f15d7eb47168e4e51cb5 to your computer and use it in GitHub Desktop.
Wordpress search - wpdb taxonomy term
<?php
$search_query = get_search_query();
$results = $wpdb->get_results("SELECT *
FROM $wpdb->terms AS wt
INNER JOIN $wpdb->term_taxonomy AS wtt ON wt.term_id=wtt.term_id
INNER JOIN $wpdb->term_relationships AS wtr ON wtr.term_taxonomy_id=wtt.term_taxonomy_id
LEFT JOIN $wpdb->posts wp ON wp.ID=wtr.object_id
WHERE taxonomy='$taxonomy' AND name LIKE '%%$search_query%%'
" );
echo '<pre>';
print_r($results);
echo '</pre>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment