Skip to content

Instantly share code, notes, and snippets.

@shazahm1
Created September 23, 2014 14:36
Show Gist options
  • Save shazahm1/84e8dce8c4eb1ede3512 to your computer and use it in GitHub Desktop.
Save shazahm1/84e8dce8c4eb1ede3512 to your computer and use it in GitHub Desktop.
Search Category Desc
<?php
function cn_search_category_description($scored, $terms) {
global $wpdb;
$select = array();
$from = array();
$joun = array();
$where = array();
$select[] = 'entry_id';
$from[] = CN_TERM_RELATIONSHIP_TABLE . ' tr';
$join[] = CN_TERM_TAXONOMY_TABLE . ' tt ON tr.term_taxonomy_id = tt.term_taxonomy_id ';
$where[] = $wpdb->prepare('MATCH (description) AGAINST (%s IN BOOLEAN MODE)', $terms);
$sql = "SELECT " . implode( ',', $select ) . " FROM " . implode( ',', $from ) . " JOIN " . implode( ',', $join ) . " WHERE " . implode( ' AND ', $where );
$ids = $wpdb->get_results( $sql, ARRAY_A );
if ( ! empty( $ids ) ) $scored = array_merge( $scored, $ids );
return $scored;
}
add_action('cn_search_scored_results', 'cn_search_category_description', 1, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment