Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('ABSPATH') or die();
- /**
- * Include posts from guest authors in the search results.
- * @author jakebellacera
- */
- add_filter('posts_clauses', 'search_posts_clauses', 10, 2);
- function search_posts_clauses($clauses, $query) {
- if (!$query->is_main_query && !$query->is_search && !$query->is_admin)
- return $clauses;
- global $wpdb;
- $clauses['join'] .= <<<SQL
- INNER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id
- INNER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
- INNER JOIN {$wpdb->terms} USING (term_id)
- SQL;
- $clauses['where'] .= $wpdb->prepare(
- " OR ({$wpdb->term_taxonomy}.taxonomy = 'author' AND {$wpdb->term_taxonomy}.description LIKE '%%%s%%' AND {$wpdb->posts}.post_type = 'post')",
- sanitize_text_field($query->query['s'])
- );
- return $clauses;
- }
Add Comment
Please, Sign In to add comment