Now, I'm creating a search page that receives, via POST
, information from a form containing several checkbox
. See below that there are several sequences of results and one orange is marked as an example:
WhenIclicksearch,theinformationissenttoapagewhereitwillcontainasequenceofif
andcase
toorganizetheinformation:
if(!isset($_POST['residencial'])&&isset($_POST['comercial'])&&isset($_POST['mecanico'])&&!isset($_POST['eletronico'])&&isset($_POST['chave'])&&isset($_POST['segredo'])&&!isset($_POST['display'])&&!isset($_POST['led'])){$var1=$_POST['residencial'].'+'.$_POST['mecanico'].'+'.$_POST['display'];}echo$var1;
RESULT:commercial+mechanical+key+secret
AfterItreatthisinformation,Itreatitasaswitch
:
switch($var1){case'comercial+mecanico+chave+segredo':$data=array('1'=>$_POST['chave'],'2'=>$_POST['segredo']);break;
Finally,Iuse$data
tofiltermyloop:
$args=array('posts_per_page'=>-1,'tax_query'=>array('relation'=>'AND',array('taxonomy'=>'product_cat','field'=>'slug',//'terms'=>'white-wines''terms'=>array($data['1'],$data['2']))),'post_type'=>'product','orderby'=>'title,');
MYDOUBTS:
HowcanIoptimizethis?Everythingworksfine,butascheckboxeshavemanypossibilities,thecodeisgettingimmense!
Combinations:(commercial+residential+mechanical+electronic+key+secret+display+led)
(commercialand/orresidential+mechanicaland/orelectronic+keyand/orsecretand/ordisplayand/orled)
UPDATE:
Theproblemisthatthereisacombinationofcheck!Example:thereisthecommercialkeyandkeyforresidentialandthekeymayormaynotbemechanicalorelectric!HowdoIdothat?
Thereisahierarchybetweenthecheck:
Comercial(categoria)
-Mecânico(sub categoria)
--Chave(sub)
--Segredo(sub)
--Display(sub)
--Led (sub)
-Eletrônico(sub categoria)
--Chave(sub)
--Segredo(sub)
--Display(sub)
--Led (sub)
Residencial(categoria)
-Mecânico
--Chave
--Segredo
--Display
--Led
-Eletrônico
--Chave
--Segredo
--Display
--Led