-
Search Results
-
I’m using the following code to match the search term to post slugs as well as match taxonomy term slugs.
This works great, except it is interfering with how the Search query works in conjunction with the other filters.
For example:
Right now I have the following lines from the below code commented out (i.e. those lines are not being executed):
add_filter('posts_where','atom_search_where'); add_filter('posts_join', 'atom_search_join');So here:
https://wtg.wpengine.com/the-library?_sft_format=blog-posts&_sf_s=evidenceIf those lines **were not commented out** the results would basically ignore the “_sft_format=blog-posts” part of the query string completely.
So I’m missing the part in my code where the search is joined with the rest of the S&F query.
Please help me identify what I can do to fix this code.
Thank you!!!
`
function sf_filter_query_args( $query_args, $sfid ) {
if(!is_library()) {
return false;
}add_filter(‘posts_where’,’atom_search_where’);
add_filter(‘posts_join’, ‘atom_search_join’);}
add_filter( ‘sf_edit_query_args’, ‘sf_filter_query_args’, 10, 2 );function atom_search_where($where){
global $wpdb;
if (is_sf_search() && isset($_GET[‘_sf_s’])) {$thesearch = $_GET[‘_sf_s’];
$thesearch = trim(rawurldecode($thesearch));$where .= “OR (t.name LIKE ‘%” . $thesearch . “%’ AND {$wpdb->posts}.post_status = ‘publish’) OR (t.slug LIKE ‘%” . $thesearch . “%’ AND {$wpdb->posts}.post_status = ‘publish’)”;
}
return $where;remove_filter(‘posts_where’,’atom_search_where’);
}function atom_search_join($join){
global $wpdb;
if (is_sf_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;remove_filter(‘posts_join’, ‘atom_search_join’);
}