Skip to content

Instantly share code, notes, and snippets.

@rolandinsh
Forked from bueltge/gist:1016587
Created April 19, 2013 14:00
Show Gist options
  • Select an option

  • Save rolandinsh/5420548 to your computer and use it in GitHub Desktop.

Select an option

Save rolandinsh/5420548 to your computer and use it in GitHub Desktop.

Revisions

  1. @bueltge bueltge revised this gist Jun 9, 2011. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,5 @@
    via http://wordpress.stackexchange.com/questions/2623/include-custom-taxonomy-term-in-search/5404#5404

    ```php
    function atom_search_where($where){
    global $wpdb;

    @@ -34,5 +33,4 @@ function atom_search_groupby($groupby){
    return $groupby . ", " . $groupby_id;
    }

    add_filter('posts_where', 'atom_search_where');
    ```
    add_filter('posts_where', 'atom_search_where');
  2. @bueltge bueltge revised this gist Jun 9, 2011. 1 changed file with 15 additions and 8 deletions.
    23 changes: 15 additions & 8 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,19 @@
    via http://wordpress.stackexchange.com/questions/2623/include-custom-taxonomy-term-in-search/5404#5404

    ```php
    function atom_search_where($where){
    global $wpdb;
    if (is_search())
    $where .= "OR (t.name LIKE '%".get_search_query()."%' AND {$wpdb->posts}.post_status = 'publish')";

    if ( is_search() )
    $where .= "OR (t.name LIKE '%".get_search_query() . "%' AND {$wpdb->posts} . post_status = 'publish')";

    return $where;
    }

    function atom_search_join($join){
    global $wpdb;
    if (is_search())

    if ( is_search() )
    $join .= "LEFT JOIN {$wpdb->term_relationships} tr ON {$wpdb->posts}.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id";
    return $join;
    }
    @@ -18,14 +22,17 @@ function atom_search_groupby($groupby){
    global $wpdb;

    // we need to group on post ID
    $groupby_id = "{$wpdb->posts}.ID";
    if(!is_search() || strpos($groupby, $groupby_id) !== false) return $groupby;
    $groupby_id = "{$wpdb->posts} . ID";
    if ( ! is_search() || strpos($groupby, $groupby_id) !== false )
    return $groupby;

    // groupby was empty, use ours
    if(!strlen(trim($groupby))) return $groupby_id;
    if ( ! strlen( trim($groupby) ) )
    return $groupby_id;

    // wasn't empty, append ours
    return $groupby.", ".$groupby_id;
    return $groupby . ", " . $groupby_id;
    }

    add_filter('posts_where','atom_search_where');
    add_filter('posts_where', 'atom_search_where');
    ```
  3. @bueltge bueltge created this gist Jun 9, 2011.
    31 changes: 31 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    via http://wordpress.stackexchange.com/questions/2623/include-custom-taxonomy-term-in-search/5404#5404

    function atom_search_where($where){
    global $wpdb;
    if (is_search())
    $where .= "OR (t.name LIKE '%".get_search_query()."%' AND {$wpdb->posts}.post_status = 'publish')";
    return $where;
    }

    function atom_search_join($join){
    global $wpdb;
    if (is_search())
    $join .= "LEFT JOIN {$wpdb->term_relationships} tr ON {$wpdb->posts}.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id=tr.term_taxonomy_id INNER JOIN {$wpdb->terms} t ON t.term_id = tt.term_id";
    return $join;
    }

    function atom_search_groupby($groupby){
    global $wpdb;

    // we need to group on post ID
    $groupby_id = "{$wpdb->posts}.ID";
    if(!is_search() || strpos($groupby, $groupby_id) !== false) return $groupby;

    // groupby was empty, use ours
    if(!strlen(trim($groupby))) return $groupby_id;

    // wasn't empty, append ours
    return $groupby.", ".$groupby_id;
    }

    add_filter('posts_where','atom_search_where');