Search in custom taxonomy

02/05/2012

Today I had to find a solution for searching custom post within custom taxonomy and displaying results in custom search template.

First of all I’ve added simple search form to category with custom posts, copied from searchform.php:

 <form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
 <input type="text" name="s" id="s" placeholder="Nazwisko..." />
 <input type="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search'); ?>" />
 </form>

Than I had to make search to look only in one taxonomy:

 <form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
 <input type="text" name="s" id="s" placeholder="Nazwisko..." />
 <input type="hidden" name='nazwisko' value='lista-nazwisk'>
 <input type="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search'); ?>" />
 </form>

where nazwisko is the name of my custom taxonomy and lista-nazwisk is a name of category created in taxonomy. Lista-nazwisk contains subcategories, and search engine will also look form posts within them.

Code above allows us to search just in custom taxonomy, but how to make separate search results template?

In my template I had a custom template for displaying custom posts – the name of template is taxonomy-nazwisko.php where “nazwisko” is the name of taxonomy. I copied this file and renamed it to search-custom.php then in search.php in the beginning I’ve added simple condition check:


if($_GET['nazwisko']){

 require_once('taxonomy-nazwisko.php');

}
else{

HERE GOES ORIGINAL search.php content

}

the condition checks if the name of taxonomy (“nazwisko”) is passed in url by search query, if so it displays search template, in other cases it will display standard search results template.

Zmiana

14/04/2012

Zmiana profilu bloga, teraz ten będzie taktował wyłącznie o developerce (czyli za dużo tutaj się nie znajdzie), natomiast prywatne wpisy bęą umieszczane na projekt365.net

Hysteria

12/03/2012


Miły lekki i przyjemny film, nawet można się zaśmiać kilka razy, polecam.

Dziewczyna z tatuażem smoka

02/03/2012

Noo, w końcu coś wartego uwagi! Przed pójściem do kina nie czytałem recenzji, ktoś mi tam powiedział że jest niezły, więc poszedłem. Światła zagasły, zaczęło się intro i już byłem pod wrażeniem – jest świetne, z genialną muzyką. Nastawiło mnie że to będzie film akcji, a tu… kryminał, dobry kryminał, może nie trzymał jakoś super w napięciu, ale cały czas trzymał wysoki poziom. Dobrze wydane 42zł. Polecam zobaczyć.

Żelazna Dama… z ołowiu…

16/02/2012

Rozczarowałem się! Spodziewałem się porywającej opowieści jak to kobieta zostaje premierem Wielkiej Brytanii, a dostałem nudną jak flaki z olejem historyjkę o staruszce z Alzheimerem mającej przebłyski wspomnień. Marylka Streep zagrała świetnie(choć akcent ma nieziemsko denerwujący), ale to za mało żeby film się podobał…