Created
December 3, 2014 15:28
-
-
Save naotone/f15d7eb47168e4e51cb5 to your computer and use it in GitHub Desktop.
Wordpress search - wpdb taxonomy term
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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