andr923 Posted January 2, 2010 Share Posted January 2, 2010 Hey everyone, I would really appreciate your help on this. I'm editing this search function for a support tickets plugin on WordPress and I can't get the search function to operate like I want it to. Basically the plugin is for residents to supply a form requesting maintenance. The support plugin sends some default keys to its database and a few keys that I could add myself it sends as "meta" keys and "meta values". As is I have edited the search so that I can search for support tickets based on just one "meta" key, but as soon as I type in a search string that might be in two different keys the search returns null. Basically, I have two meta keys "building" and "unit_number" that I would be able to search for at the same time, but it will only search through one or the other. Weirdly enough, I can search through "building" and "author_name" (author name is one of the defaults) at the same time, or "unit_number" and "author_name" but not two meta keys. Any help would be soooo much appreciated. I'm sure it's a small thing I can't figure out, but it would go a long way! here's the code... function suptic_icl_get_tickets_by_language( $lang = '', $args = '' ) { global $wpdb; if ( ! $lang ) return suptic_get_tickets( $args ); $defaults = array( 'perpage' => 0, 'offset' => 0, 'orderby' => 'id', 'status' => array(), 'search' => '' ); $args = wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); $tickets_table = suptic_db_table( 'tickets' ); $messages_table = suptic_db_table( 'messages' ); $meta_table = suptic_db_table( 'meta' ); $tr_table = $wpdb->prefix . 'icl_translations'; $query = "SELECT DISTINCT tickets.* FROM $tickets_table as tickets" . " INNER JOIN $tr_table AS tc ON tickets.id = tc.element_id" . " AND tc.element_type LIKE 'suptic-ticket'" . " LEFT JOIN $messages_table AS messages ON ticket_id = tickets.id" . " LEFT JOIN $meta_table AS meta ON object_type LIKE 'ticket' AND object_id = tickets.id" . " WHERE ticket_type LIKE 'ticket'" . $wpdb->prepare( " AND language_code LIKE %s", $lang ); if ( is_array( $status ) && ! empty( $status ) ) { $query .= " AND (1=0"; foreach ( $status as $s ) { $query .= $wpdb->prepare( " OR tickets.status LIKE %s", '%' . $s . '%' ); } $query .= ")"; } if ( $search = trim( stripslashes( $search ) ) ) { $search = explode( ' ', $search ); foreach( $search as $s ) { $query .= " AND (1 = 0"; $query .= $wpdb->prepare( " OR subject LIKE %s", '%' . $s . '%' ); $query .= $wpdb->prepare( " OR author_email LIKE %s", '%' . $s . '%' ); $query .= $wpdb->prepare( " OR author_first_name LIKE %s", '%' . $s . '%' ); $query .= $wpdb->prepare( " OR author_last_name LIKE %s", '%' . $s . '%' ); $query .= $wpdb->prepare( " OR message_body LIKE %s", '%' . $s . '%' ); $query .= $wpdb->prepare( " OR (meta_key NOT LIKE '_%' AND meta_value LIKE %s)", '%' . $s . '%' ); $query .= ")"; } } if ( 'update_time' == $orderby ) $query .= " ORDER BY tickets.update_time DESC"; elseif ( 'create_time' == $orderby ) $query .= " ORDER BY tickets.create_time DESC"; else $query .= " ORDER BY tickets.id ASC"; if ( $offset && $perpage ) { $query .= $wpdb->prepare( " LIMIT %d,%d", $offset, $perpage ); } elseif ( $perpage ) { $query .= $wpdb->prepare( " LIMIT %d", $perpage ); } if ( $result = $wpdb->get_results( $query ) ) { $tickets = array(); foreach ( $result as $t ) { $tickets[] = new SupTic_Ticket( $t ); } return $tickets; } return null; } Thanks a lot!!!! Link to comment https://forums.phpfreaks.com/topic/186892-wp-plugin-search-question/ Share on other sites More sharing options...
andr923 Posted January 2, 2010 Author Share Posted January 2, 2010 I keep trying to change the elements of the query, but still no luck... anyone? Link to comment https://forums.phpfreaks.com/topic/186892-wp-plugin-search-question/#findComment-987288 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.