Guest User

Untitled

a guest
Jul 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. <?php defined('ABSPATH') or die();
  2.  
  3. /**
  4. * Include posts from guest authors in the search results.
  5. * @author jakebellacera
  6. */
  7. add_filter('posts_clauses', 'search_posts_clauses', 10, 2);
  8. function search_posts_clauses($clauses, $query) {
  9. if (!$query->is_main_query && !$query->is_search && !$query->is_admin)
  10. return $clauses;
  11.  
  12. global $wpdb;
  13.  
  14. $clauses['join'] .= <<<SQL
  15. INNER JOIN {$wpdb->term_relationships} ON {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id
  16. INNER JOIN {$wpdb->term_taxonomy} USING (term_taxonomy_id)
  17. INNER JOIN {$wpdb->terms} USING (term_id)
  18. SQL;
  19.  
  20. $clauses['where'] .= $wpdb->prepare(
  21. " OR ({$wpdb->term_taxonomy}.taxonomy = 'author' AND {$wpdb->term_taxonomy}.description LIKE '%%%s%%' AND {$wpdb->posts}.post_type = 'post')",
  22. sanitize_text_field($query->query['s'])
  23. );
  24.  
  25. return $clauses;
  26. }
Add Comment
Please, Sign In to add comment