Lozinspain
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Plugins
In reply to: [Faceted Search] Ordering results by custom fieldsorry important copy and paste error – lost an important “if” – above should read
`if (isset($_REQUEST[‘paged’]) || isset($_GET[‘facetedsearch’]))Forum: Plugins
In reply to: [Faceted Search] Ordering results by custom fieldshould have said in case it’s not already obvious, my meta_key, the price which I wanted parsed as a number, is “true_price”
Forum: Plugins
In reply to: [Faceted Search] Ordering results by custom fieldFinally solved this issue myself. I’m using the plug-in on a real estate site and needed to have the results ordered by property price asc rather than post date. In case this is of any use to anybody the code that I modified in faceted-search.php ended up as follows:
function facetedsearch_simple_query($effective_array, $descendant_array, $and_or) { global $wpdb; $query = 'SELECT SQL_CALC_FOUND_ROWS DISTINCT * '; $queryfrom = 'FROM '.$wpdb->posts; $querywhere = " INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND post_type = 'post' AND post_status = 'publish' AND ("; //see if the current foreach loop has run at least once $ran_once = 0; //loop through all selected terms foreach ($effective_array as $id) { //validate the value before inserting it into the query if (is_numeric($id)) { if($ran_once == 1) { $querywhere .= ' '.$and_or.' '; } $in_string = implode(',',$descendant_array[$id]).','; $in_string .= $id; $in_string = trim($in_string,','); //get the object id of each post associated with the the current term id and its descendants $querywhere .= '(ID in (SELECT tr'.$id.'.object_id FROM '.$wpdb->term_relationships.' tr'.$id.', '.$wpdb->term_taxonomy.' tt'.$id.' WHERE tt'.$id.'.term_id in('.$in_string.') AND tr'.$id.'.term_taxonomy_id = tt'.$id.'.term_taxonomy_id)'; $querywhere .= ')'; $ran_once = 1; } } if ( $ran_once == 1) { $querywhere .= ') AND (wp_postmeta.meta_key = "true_price" ) GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC'; (isset($_REQUEST['paged']) || isset($_GET['facetedsearch'])) { $offset = 10*intval($_REQUEST['paged']); $offset = $offset > 0 ? $offset - 10 : 0; $querywhere .= ' LIMIT '.$offset.',10'; } $query = $query.$queryfrom.$querywhere; return ($query); } else { return ''; } }
Viewing 3 replies - 1 through 3 (of 3 total)