Advertisement
miriamdepaula

WordPress: Custom Searches

Nov 8th, 2011
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. <?php
  2. function custom_search_where($where) {
  3.     // put the custom fields into an array
  4.     $customs = array('custom_field1', 'custom_field2', 'custom_field3');
  5.  
  6.     foreach($customs as $custom) {
  7.     $query .= " OR (";
  8.     $query .= "(m.meta_key = '$custom')";
  9.     $query .= " AND (m.meta_value  LIKE '{$n}{$term}{$n}')";
  10.         $query .= ")";
  11.     }
  12.  
  13.     $where = " AND ({$query}) AND ($wpdb->posts.post_status = 'publish') ";
  14.     return($where);
  15. }
  16. add_filter('posts_where', 'custom_search_where');
  17.  
  18. ?>
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement