Find answers, ask questions, and connect with our
community around the world.

Forums Forums Web Design WordPress Modify search query to include taxonomies

  • Modify search query to include taxonomies

    updated 3 years, 5 months ago 0 Member · 1 Post
  • Deborah

    Member
    September 4, 2019 at 5:32 pm

    This is a function to include specific custom taxonomies into the search query for WordPress. It works alongside searching for title and everything else because it uses an OR statement instead of the original AND statement. function _pd_search_taxonomy( $clauses, $query ) { // IGNORE ADMIN REQUESTS if ( is_admin() ) { return $clauses; } global $wpdb; if($query->query_vars){ // GET THE SEARCH TERM $searchterm = $query->query_vars[‘s’]; } $clauses[‘join’] .= term_relationships}.object_id LEFT OUTER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id) LEFT OUTER JOIN {$wpdb->terms} USING (term_id) SQL; // REPLACE taxonomy = WITH YOUR OWN TAXONOMY SLUG $clauses[‘where’] .= ” OR (taxonomy = ‘sub_search_terms’ AND taxonomy IS NOT NULL AND $wpdb->terms.slug = ‘” . $searchterm . “‘)”; return $clauses; } add_filter( ‘posts_clauses’, ‘_pd_search_taxonomy’, 10, 2 ); – by hq overview pixeldevs – –

Viewing 1 of 1 replies
Reply to: Deborah
Your information:

Cancel
Original Post
0 of 0 posts June 2018
Now