Custom addition to search
-
Hey guys,
I’m trying to setup a modification to the search function to search through custom meta fields on products. This is using the WordPress shopping cart plugin, but interacting with the default WordPress tables.
Currently I have the following code:
add_filter('posts_join', 'custom_search_metadata_join'); add_filter('posts_where', 'custom_search_metadata'); function custom_search_metadata_join($join) { global $wp_query, $wpdb; if(!empty($_REQUEST['product_search'])) { $join .= "LEFT JOIN (SELECT post_id, meta_value from $wpdb->postmeta where $wpdb->postmeta.meta_key = '_wpsc_album') as album_name_meta on $wpdb->posts.ID = album_name_meta.post_id"; } error_log("metadata join: ".$join); return $join; } function custom_search_metadata($where) { global $wp_query; if(!empty($_REQUEST['product_search'])) { $where .= " OR (album_name_meta.meta_value like '%" . $_REQUEST['product_search'] . "%' $where)"; } error_log("metadata where: ". $where); return $where; }
The custom meta fields in this case are _wpsc_album.
I’ve been away from this project and just come back to it, and I’m sure this script HAD been working the last time I’d looked at it.
I would greatly appreciate your help!
- The topic ‘Custom addition to search’ is closed to new replies.