Last active
August 29, 2015 14:17
-
-
Save ivanhoe011/a47113d11904ae3decc3 to your computer and use it in GitHub Desktop.
Advanced search example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// filter je upit koji zavisi od toga sta je popunjeno u pretrazi | |
$filter = array('relation' => 'AND'); | |
// zavisno sta je od polja poslato u upitu kreiramo upit: | |
if ( ! empty($_GET['tip'])) { // ako pretrazujes po tipu nekretnine | |
$filter[] = array( | |
'key' => 'tip', // ovo je ime custom polja, recimo da je 'tip' | |
'value' => $_GET['tip'], | |
'compare' => '=', | |
); | |
} | |
if ( ! empty($_GET['cena'])) { // ako pretrazujes po ceni | |
$filter[] = array( | |
'key' => 'cena', | |
'value' => $_GET['cena'], | |
'compare' => '<=', | |
); | |
} | |
// itd... | |
// sastavis to sve u jedan niz argumenata | |
$args = array( | |
'post_type' => 'stanovi', // ovde stavis kako ti se zove custom post type | |
'meta_query' => $filter, // <--- ovde ubacujemo sve uslove za custom polja | |
'orderby' => 'vazi_do', // sortiramo npr. po nekom datumu do kad vazi oglas | |
'order' => 'DESC', | |
); | |
$loop = new WP_Query( $args ); | |
if($loop->have_posts()): while ($loop->have_posts()) : $loop->the_post(); | |
?> | |
Ovo je dalje kao klasican WP loop... | |
<?php endwhile; endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment