Important security update, please update to Osclass 3.7.4
At Osclass we have changed our Privacy Policy and Terms of Use in order to adapt them to the new General Data Protection Regulation (GDPR). We want you to know what user data we store, what we need them for, and who we share them with in each specific case. Furthermore, we are making it even easier for you to exercise your right to manage your own data.
Our goal is that you enjoy the best possible experience with our website. As the GDPR comes into force, legislation requires us that you grant us permission—both to us and our partners—to store cookies in your browser. Remember you can find more information about what we do with your data by clicking here.
I accept Osclass SL’s Terms of Use and Cookies Policy and grant them permission to manage my data.
$from = $aux['from']; $to = $aux['to']; $start = Search::newInstance()->dao->escape($from); $end = Search::newInstance()->dao->escape($to);
***CORRECTED AGAIN***Hi,Here's a way to achieve that:Add this at the very bottom of your theme functions.php:Notes:1.- Take care not to leave blank lines after this.2.- If your theme functions.php doesn't end with ?> skip first line of my code.Code: [Select]<?phpfunction cust_global_custom_field_form() { if(!osc_search_category_id()) { $global_custom_fields = array('dropdown-1', 'other-dropdown'); // Put here one or more custom fields slugs $nField = new Field(); foreach ($global_custom_fields AS $slug) { $global_custom_field = $nField->findBySlug($slug); FieldForm::meta($global_custom_field, true); echo "<p></p>"; } }}osc_add_hook('search_form', 'cust_global_custom_field_form');function cust_global_custom_field_search_conditions($params) { if (@$params['meta'] && !@$params['sCategory']) { $metas = $params['meta']; $mSearch = Search::newInstance(); $table = DB_TABLE_PREFIX.'t_item_meta'; foreach ($metas as $key => $aux) { $cField = new Field(); $field = $cField->findByPrimaryKey($key); switch ($field['e_type']) { case 'TEXTAREA': case 'TEXT': case 'URL': if($aux!='') { $aux = "%$aux%"; $sql = "SELECT fk_i_item_id FROM $table WHERE "; $str_escaped = $mSearch->dao->escape($aux); $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value LIKE ".$str_escaped; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DROPDOWN': case 'RADIO': if($aux!='') { $sql = "SELECT fk_i_item_id FROM $table WHERE "; $str_escaped = $mSearch->dao->escape($aux); $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value = ".$str_escaped; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'CHECKBOX': if($aux!='') { $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value = 1"; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DATE': if($aux!='') { $y = (int)date('Y', $aux); $m = (int)date('n', $aux); $d = (int)date('j', $aux); $start = mktime('0', '0', '0', $m, $d, $y); $end = mktime('23', '59', '59', $m, $d, $y); $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value >= ".($start)." AND "; $sql .= $table.".s_value <= ".$end; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DATEINTERVAL': if( is_array($aux) && (!empty($aux['from']) && !empty($aux['to'])) ) { $from = $aux['from']; $to = $aux['to']; $start = $from; $end = $to; $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $start." >= ".$table.".s_value AND s_multi = 'from'"; $sql1 = "SELECT fk_i_item_id FROM $table WHERE "; $sql1 .= $table.".fk_i_field_id = ".$key." AND "; $sql1 .= $end." <= ".$table.".s_value AND s_multi = 'to'"; $sql_interval = "select a.fk_i_item_id from (".$sql.") a where a.fk_i_item_id IN (".$sql1.")"; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql_interval.')'); } break; default: break; } } }}osc_add_hook('search_conditions', 'cust_global_custom_field_search_conditions');?>You need to manually set one or several "global" custom fields using their slug (Identifier name) to identify them:Quote$global_custom_fields = array('dropdown-1', 'other-dropdown'); // Put here one or more custom fields slugsRegards
<?phpfunction cust_global_custom_field_form() { if(!osc_search_category_id()) { $global_custom_fields = array('dropdown-1', 'other-dropdown'); // Put here one or more custom fields slugs $nField = new Field(); foreach ($global_custom_fields AS $slug) { $global_custom_field = $nField->findBySlug($slug); FieldForm::meta($global_custom_field, true); echo "<p></p>"; } }}osc_add_hook('search_form', 'cust_global_custom_field_form');function cust_global_custom_field_search_conditions($params) { if (@$params['meta'] && !@$params['sCategory']) { $metas = $params['meta']; $mSearch = Search::newInstance(); $table = DB_TABLE_PREFIX.'t_item_meta'; foreach ($metas as $key => $aux) { $cField = new Field(); $field = $cField->findByPrimaryKey($key); switch ($field['e_type']) { case 'TEXTAREA': case 'TEXT': case 'URL': if($aux!='') { $aux = "%$aux%"; $sql = "SELECT fk_i_item_id FROM $table WHERE "; $str_escaped = $mSearch->dao->escape($aux); $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value LIKE ".$str_escaped; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DROPDOWN': case 'RADIO': if($aux!='') { $sql = "SELECT fk_i_item_id FROM $table WHERE "; $str_escaped = $mSearch->dao->escape($aux); $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value = ".$str_escaped; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'CHECKBOX': if($aux!='') { $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value = 1"; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DATE': if($aux!='') { $y = (int)date('Y', $aux); $m = (int)date('n', $aux); $d = (int)date('j', $aux); $start = mktime('0', '0', '0', $m, $d, $y); $end = mktime('23', '59', '59', $m, $d, $y); $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value >= ".($start)." AND "; $sql .= $table.".s_value <= ".$end; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DATEINTERVAL': if( is_array($aux) && (!empty($aux['from']) && !empty($aux['to'])) ) { $from = $aux['from']; $to = $aux['to']; $start = $from; $end = $to; $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $start." >= ".$table.".s_value AND s_multi = 'from'"; $sql1 = "SELECT fk_i_item_id FROM $table WHERE "; $sql1 .= $table.".fk_i_field_id = ".$key." AND "; $sql1 .= $end." <= ".$table.".s_value AND s_multi = 'to'"; $sql_interval = "select a.fk_i_item_id from (".$sql.") a where a.fk_i_item_id IN (".$sql1.")"; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql_interval.')'); } break; default: break; } } }}osc_add_hook('search_conditions', 'cust_global_custom_field_search_conditions');?>
$global_custom_fields = array('dropdown-1', 'other-dropdown'); // Put here one or more custom fields slugs
<?phpfunction cust_global_custom_field_form() { if(!osc_search_category_id()) { $global_custom_fields = array('dropdown-1', 'other-dropdown'); // Put here one or more custom fields slugs $nField = new Field(); foreach ($global_custom_fields AS $slug) { $global_custom_field = $nField->findBySlug($slug); FieldForm::meta($global_custom_field, true); echo "<p></p>"; } }}osc_add_hook('search_form', 'cust_global_custom_field_form');function cust_global_custom_field_search_conditions($params) { if (@$params['meta'] && !@$params['sCategory']) { $metas = $params['meta']; $mSearch = Search::newInstance(); $table = DB_TABLE_PREFIX.'t_item_meta'; foreach ($metas as $key => $aux) { $cField = new Field(); $field = $cField->findByPrimaryKey($key); switch ($field['e_type']) { case 'TEXTAREA': case 'TEXT': case 'URL': if($aux!='') { $aux = "%$aux%"; $sql = "SELECT fk_i_item_id FROM $table WHERE "; $str_escaped = $mSearch->dao->escape($aux); $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value LIKE ".$str_escaped; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DROPDOWN': case 'RADIO': if($aux!='') { $sql = "SELECT fk_i_item_id FROM $table WHERE "; $str_escaped = $mSearch->dao->escape($aux); $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value = ".$str_escaped; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'CHECKBOX': if($aux!='') { $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value = 1"; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DATE': if($aux!='') { $y = (int)date('Y', $aux); $m = (int)date('n', $aux); $d = (int)date('j', $aux); $start = mktime('0', '0', '0', $m, $d, $y); $end = mktime('23', '59', '59', $m, $d, $y); $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $table.".s_value >= ".($start)." AND "; $sql .= $table.".s_value <= ".$end; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; case 'DATEINTERVAL': if( is_array($aux)) { if(!empty($aux['to']) && empty($aux['from'])) $aux['from'] = '0'; if(!empty($aux['from']) && empty($aux['to'])) $aux['to'] = '253202544000'; $from = $aux['from']; $to = $aux['to']; $end = $to; $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND '; $sql .= $start." >= ".$table.".s_value AND s_multi = 'from'"; $sql1 = "SELECT fk_i_item_id FROM $table WHERE "; $sql1 .= $table.".fk_i_field_id = ".$key." AND "; $sql1 .= $end." <= ".$table.".s_value AND s_multi = 'to'"; $sql_interval = "select a.fk_i_item_id from (".$sql.") a where a.fk_i_item_id IN (".$sql1.")"; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql_interval.')'); } break; case 'NUMERIC': if( is_array($aux)) { if(!empty($aux['to']) && empty($aux['from'])) $aux['from'] = '-1000000'; if(!empty($aux['from']) && empty($aux['to'])) $aux['to'] = '10000000'; $from = $aux['from']; $to = $aux['to']; $start = Search::newInstance()->dao->escape($from); $end = Search::newInstance()->dao->escape($to); $sql = "SELECT fk_i_item_id FROM $table WHERE "; $sql .= $table.'.fk_i_field_id = '.$key.' AND CAST('; $sql .= $start." AS SIGNED) <= CAST(".$table.".s_value AS SIGNED) AND CAST(".$end." AS SIGNED) >= CAST(".$table.".s_value AS SIGNED)"; $mSearch->addConditions(DB_TABLE_PREFIX.'t_item.pk_i_id IN ('.$sql.')'); } break; default: break; } } }}osc_add_hook('search_conditions', 'cust_global_custom_field_search_conditions');?>