Adding multiple hidden fields to filter wordpress search

Posted on 4th March, 2017 186 Comments

To add multiple fields you’ll first need to create a small funciton in your functions.php

 

/**
 * Custom Search Queries 
 * Allows the use of multiple hidden filters on search.php
 *************************************************************/
function SearchFilter($query) {
$post_type = $_GET['post_type'];
if (!$post_type) {
    $post_type = 'any';
}
if ($query->is_search) {
    $query->set('post_type', $post_type);
};
return $query;
} 

Then in your searchform.php you can add hidden fields like this.

<form method="get" action="<?php bloginfo('url'); ?>/">
	<label for="s">Search the site: </label>
	<input type="text" id="s" name="s" value="<?php the_search_query(); ?>">

	<!-- Search only these custom post types -->
			<input type="hidden" name="post_type[]" value="page">
			<input type="hidden" name="post_type[]" value="services">
			<input type="hidden" name="post_type[]" value="solutions">
			<input type="hidden" name="post_type[]" value="resources">
			<input type="hidden" name="post_type[]" value="technology">
			<input type="hidden" name="post_type[]" value="about">
	<input type="submit" value="Search">
</form>

If you want to do this with any other filter, for example categories. Repeat the above and replace post_type with cat.

Comments

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]

JamesVen

21st, Oct, 20

Bxefec wtbmya [url=https://ciamedusa.com/]generic cialis tadalafil[/url] Dsziga mofvww cialis pharmacy tadalafil cialis

JamesVen

22nd, Oct, 20

Jbcpbl xhxroj price of cialis cialis pills [url=https://ciamedusa.com/#]buy cheap cialis online[/url] attitude marker is water to other to facilitating moment, it.

Barney

24th, Oct, 20

I visited many blogs but the audio quality for audio songs current at
this site is truly fabulous.

Life Experience Degree

27th, Oct, 20

We stumbled over here from a different web address
and thought I might check things out. I like what I see so
now i’m following you. Look forward to looking at your web page repeatedly.

https://genqpviag.com

04th, Nov, 20

Visit the Michigan Asthma Interventions page to learn how the
MDHHS Asthma Program is helping people with asthma and the health
professionals who care for them. female viagra generic name (https://genqpviag.com) why is there
no generic viagra

llviabest.com

05th, Nov, 20

Attachment 2: Draft revised Standards for Assessment
and Accreditation of Specialist Medical Education Programs
and Professional Development Programs by the Australian Medical Council — July 2015.

buy cheap viagra online (llviabest.com) viagra online without pre

Serena

06th, Nov, 20

Article writing is also a fun, if you be familiar with afterward you can write otherwise it is complicated
to write.

cialissr

06th, Nov, 20

cialis website [url=https://ciiialis.com/#]maximum dose of cialis[/url] brand cialis 100mg

Mei

08th, Nov, 20

Whats up very nice website!! Guy .. Excellent .. Amazing ..

I will bookmark your website and take the feeds also?
I’m satisfied to find numerous helpful information here in the post,
we want work out extra techniques in this regard, thanks for sharing.
. . . . .

Ronny

08th, Nov, 20

I’m not that much of a online reader to be honest but your sites
really nice, keep it up! I’ll go ahead and bookmark your site to come back in the future.
Cheers

Alberto

08th, Nov, 20

Hello, I enjoy reading through your post. I like to write a
little comment to support you.

June

08th, Nov, 20

Its like you read my mind! You seem to know so much approximately this, such as you wrote the ebook in it or something.
I think that you can do with a few percent to drive the message house a little bit, but instead of that, this is excellent
blog. A fantastic read. I will certainly be
back.

www.XMC.pl

10th, Nov, 20

Intriguing content jogs my memory of some other jewel. God heals and the doctor takes the fee. Benjamin Franklin 1706 1790

Cissr

12th, Nov, 20

Generic
buy cialis online nz [url=https://cciialiss.com/]cialis miami[/url] dose use cialis

Cissr

12th, Nov, 20

Generic
cialis erectile dysfunction [url=https://cciialiss.com/]buy cialis in usa[/url] cialis lorazepam

Cissr

13th, Nov, 20

Generic
cialis in nz [url=https://cciialiss.com/]generic cialis buy[/url] using cialis with diabetes

Cissr

13th, Nov, 20

USA
cialis good prostate [url=https://cciialiss.com/]no prescription cialis[/url] get cialis fast

Cissr

13th, Nov, 20

USA
headache on cialis [url=https://cciialiss.com/]cialis online[/url] cialis costs per pill

Cciialiss

13th, Nov, 20

Generic
cialis mastercard [url=https://cciialiss.com/]buy cialis 40 mg[/url] buy cialis online cheapest

Cciialiss

13th, Nov, 20

Generic
cialis yellow [url=https://cciialiss.com/#]buy online[/url] difference between doses cialis

Cciialiss

13th, Nov, 20

USA
buy cialis ireland [url=https://cciialiss.com/]cciialisscom[/url] generic cialis online europe

Cciialiss

13th, Nov, 20

Brand
certified pharmacy cialis [url=https://cciialiss.com/]cialis[/url] tadalafil information

Cciialiss

13th, Nov, 20

Generic
order cialis overnight [url=https://cciialiss.com/]cialis[/url] discount brand cialis

Cciialiss

13th, Nov, 20

Generic
buy cialis uk [url=https://cciialiss.com/]buy cialis brand[/url] cialis with food

Cciialiss

13th, Nov, 20

USA
best place generic cialis [url=https://cciialiss.com/]cialis 20mg[/url] is generic cialis good

Cciialiss

14th, Nov, 20

Brand
tadalafil over the counter [url=https://cciialiss.com/]cciialisscom[/url] overnight delivery of cialis

Cciialiss

14th, Nov, 20

USA
date validite cialis [url=https://cciialiss.com/]buy cialis usa[/url] generic cialis mexico

Cciialiss

14th, Nov, 20

USA
low price on cialis [url=https://cciialiss.com/#]cciialiss[/url] order cialis online india

Cciialiss

14th, Nov, 20

Generic
cialis with dapoxetine review [url=https://cciialiss.com/]buy cialis online[/url] cialis last 3 days

Cciialiss

14th, Nov, 20

USA
cialis better performance [url=https://cciialiss.com/]buy cialis online[/url] cialis effect for women

Cciialiss

14th, Nov, 20

Generic
cialis experience [url=https://cciialiss.com/]buy cialis[/url] buy cialis online india

Cciialiss

14th, Nov, 20

Brand
effects cialis eyes [url=https://cciialiss.com/]generic cialis buy[/url] brand cialis 100mg

Cciialiss

14th, Nov, 20

USA
order cialis on internet [url=https://cciialiss.com/]au cialis[/url] indian made cialis

Cciialiss

14th, Nov, 20

Brand
cialis effect on eyes [url=https://cciialiss.com/]best generic cialis[/url] effexor cialis

Cciialiss

15th, Nov, 20

USA
cialis from germany [url=https://cciialiss.com/]5mg cialis[/url] cialis online preise

Cciialiss

15th, Nov, 20

Brand
tadalafil buy online [url=https://cciialiss.com/]buy cialis in usa[/url] buy inexpensive cialis

Cciialiss

15th, Nov, 20

Generic
purchase cialis daily use [url=https://cciialiss.com/]cialis generic online pharmacy[/url] voucher for cialis

Cciialiss

15th, Nov, 20

Brand
pharmacy india cialis [url=https://cciialiss.com/]cialis online[/url] cialis in your 30s

Cciialiss

15th, Nov, 20

Brand
tadalafil usa [url=https://cciialiss.com/]cialis 20mg pills[/url] cialis miligramas

Cciialiss

15th, Nov, 20

USA
cialis dose inicial [url=https://cciialiss.com/]buy cialis overnight[/url] cost cialis costco

Cciialiss

16th, Nov, 20

Generic
cialis users review [url=https://cciialiss.com/]buy cialis[/url] cialis for threeways

Cciialiss

16th, Nov, 20

Brand
cialis reactions [url=https://cciialiss.com/]cialis miami[/url] cialis levitra online

Cciialiss

16th, Nov, 20

Brand
cialis pills india [url=https://cciialiss.com/]cialis without prescriptions[/url] organic cialis

Cciialiss

16th, Nov, 20

Brand
cialis daily use experience [url=https://cciialiss.com/]buy cialis australia[/url] medical name cialis

Cciialiss

16th, Nov, 20

Generic
buy cialis walmart [url=https://cciialiss.com/]tadalafil cialis[/url] cialis ed generic

Cciialiss

16th, Nov, 20

Generic
cialis daily pricing [url=https://cciialiss.com/]generic cialis[/url] will cialis do

ccialisny

17th, Nov, 20

generic cialis from eu [url=https://ccialisny.com/]order original cialis online[/url] generic cialis cheapest

ccialisny

17th, Nov, 20

generic cialis efficacy [url=https://ccialisny.com/]generic cialis order online[/url] effective cialis dose

ccialisny

18th, Nov, 20

cialis review women [url=https://ccialisny.com/]order cheap cialis online[/url] cialis pill look like

ccialisny

18th, Nov, 20

know if need cialis [url=https://ccialisny.com/]cialis mail order[/url] cialis most effective

ccialisny

18th, Nov, 20

cialis uk pharmacy [url=https://ccialisny.com/]cialis order online nz[/url] cialis online doctor

llevitraaa

19th, Nov, 20

le levitra ou le cialis [url=https://llevitraa.com/]generic levitra buy online australia[/url] levitra kaufen preisvergleich

llevitraaa

19th, Nov, 20

wirkung von levitra generika [url=https://llevitraa.com/]levitra sample online pharmacy[/url] levitra 20 vs viagra 100

llevitraaa

19th, Nov, 20

levitra generico commenti [url=https://llevitraa.com/]levitra buy online[/url] kamagra o levitra

llevitraaa

20th, Nov, 20

levitra odt 10 mg bayer [url=https://llevitraa.com/]buy levitra[/url] levitra nicht verschreibungspflichtig

llevitraaa

20th, Nov, 20

levitra 20 mg instructions [url=https://llevitraa.com/]buy levitra[/url] levitra canada pharmacy

llevitraaa

20th, Nov, 20

acquisto levitra in contrassegno [url=https://llevitraa.com/]levitra buy online[/url] pastillas levitra para que sirven

llevitraaa

20th, Nov, 20

wie muss ich levitra einnehmen [url=https://llevitraa.com/]generic levitra buy india[/url] levitra discounts

llevitraaa

20th, Nov, 20

levitra ciao [url=https://llevitraa.com/]levitra buy online uk[/url] erfahrungen levitra 20mg

llevitraaa

20th, Nov, 20

levitra issues [url=https://llevitraa.com/]levitra buy online is it safe[/url] levitra 20 mg of cialis

llevitraaa

20th, Nov, 20

levitra orosolubile opinioni [url=https://llevitraa.com/]generic levitra buy[/url] levitra bula completa

Andrewreigo

21st, Nov, 20

male potency pills [url=https://hipotencyrx.com/]potency pills[/url] brand and generic in best prices with fast shipping!

llevitraaa

21st, Nov, 20

levitra 20 mg satin al [url=https://llevitraa.com/]generic levitra online pharmacy[/url] vardenafil levitra 20mg

fixcialel

24th, Nov, 20

cialis how fast [url=https://cialisfix.com/]cialis prices in new zealand[/url] cialis first dose

fixcialel

24th, Nov, 20

cialis professional vs cialis [url=https://cialisfix.com/]goodrx cialis 5[/url] generic cialis 30

fixcialel

25th, Nov, 20

cialis brug [url=https://cialisfix.com/]order generic cialis online[/url] discount card for cialis

fixcialel

25th, Nov, 20

cialis generic real [url=https://cialisfix.com/]ordering cialis in canada[/url] cialis libido

fixcialel

25th, Nov, 20

cialis instructions use [url=https://cialisfix.com/]https://cialisfix.com/#[/url] do cialis pills do

ciialel

28th, Nov, 20

cialis jelly [url=https://cciialiis.com/]cialis professional wikipedia[/url] buy 36 hour cialis

ciialel

28th, Nov, 20

new use for cialis [url=https://cciialiis.com/]order cialis overnight delivery[/url] cialis boost

ciialel

29th, Nov, 20

what is cialis pills [url=https://cciialiis.com/]https://cciialiis.com/#[/url] ok cut cialis half

ciialel

29th, Nov, 20

buy cialis miami [url=https://cciialiis.com/]cialis frequency of use[/url] buy cialis online ireland

ciialel

29th, Nov, 20

cialis 10mg price [url=https://cciialiis.com/]order cialis online overnight[/url] cialis daily use directions

Cciialiss

29th, Nov, 20

Brand
cheapest price generic cialis [url=https://cciialiss.com/]order cialis 20 mg[/url] is cialis enteric coated

Cciialiss

29th, Nov, 20

Brand
cialis for hair loss [url=https://cciialiss.com/]order cialis online[/url] does tadalafil work

Cciialiss

30th, Nov, 20

USA
man health cialis [url=https://cciialiss.com/]order generic cialis online[/url] contraindicaciones de cialis

Cciialiss

30th, Nov, 20

Generic
knight medicare cialis [url=https://cciialiss.com/]order cialis 20 mg[/url] cialis canada

Cciialiss

30th, Nov, 20

USA
cialis user reviews [url=https://cciialiss.com/]order generic cialis[/url] cialis pills men

Cciialiss

01st, Dec, 20

Brand
cialis moment [url=https://cciialiss.com/]cialis order online[/url] cialis in ungarn

Cciialiss

01st, Dec, 20

USA
generic cialis fast shipping [url=https://cciialiss.com/]order cialis miami[/url] original cialis holland

Cciialiss

01st, Dec, 20

Generic
tadalafil citrate dosage [url=https://cciialiss.com/]order cialis with dapoxtine[/url] levitra o cialis

llevitraaa

02nd, Dec, 20

can levitra cause delayed ejaculation [url=https://llevitraa.com/]bayer levitra buy[/url] viagra cialis levitra precio

llevitraaa

02nd, Dec, 20

perbandingan levitra vs viagra [url=https://llevitraa.com/]levitra buy online australia cheapest[/url] levitra precio en bogota

Leave a Comment

To preserve code added to a comment you can wrap your code in short tags
by using [square brackets]:

  1. PHP use - [php] <?php code here ?> [/php]
  2. CSS use - [css] #code-here {} [/css]
  3. HTML use - [html] <div> code here </div> [/html]
  4. JS use - [js] $(".codeHere") [/js]