Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function __pesquisa_por_title( $search, &$wp_query )
- {
- if ( empty($search) )
- return $search;
- $q =& $wp_query->query_vars;
- // linhas do wp-includes/query.php - wp3.1
- $n = !empty($q['exact']) ? '' : '%';
- $searchand = '';
- foreach( (array) $q['search_terms'] as $term ) {
- $term = esc_sql( like_escape( $term ) );
- $search .= "{$searchand}($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
- $searchand = ' AND ';
- }
- $term = esc_sql( like_escape( $q['s'] ) );
- if ( empty($q['sentence']) && count($q['search_terms']) > 1 && $q['search_terms'][0] != $q['s'] )
- $search .= " OR ($wpdb->posts.post_title LIKE '{$n}{$term}{$n}')";
- if ( !empty($search) ) {
- $search = " AND ({$search}) ";
- if ( !is_user_logged_in() )
- $search .= " AND ($wpdb->posts.post_password = '') ";
- }
- return $search;
- }
- add_filter( 'posts_search', '__pesquisa_por_title', 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment