Last active
July 12, 2018 11:10
-
-
Save sxidsvit/846a443a0ced08c15b5d7df829fa002c to your computer and use it in GitHub Desktop.
Фильтр для работы с таксономиями и мета данными - А.Сокирка. Интенсив 21.05-25.05.2018
This file contains 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 ********************************// | |
<?php | |
function filter_deals_example($data){ | |
$args = array( | |
'posts_per_page' => '5', | |
'post_type' => 'deals', | |
'tax_query' => array( | |
'relation' => 'AND' | |
) | |
); | |
if(isset($data['intensiv_location']) && isset($data['intensiv_location']) !== '') { | |
array_push($args['tax_query'], array( | |
'taxonomy'=>'location', | |
'terms' => array($data['intensiv_location']) | |
)); | |
} | |
if(isset($data['intensiv_type']) && isset($data['intensiv_type']) !== '') { | |
array_push($args['tax_query'], array( | |
'taxonomy'=>'type', | |
'terms' => array($data['intensiv_type']) | |
)); | |
} | |
if(isset($data['intensiv_price']) && isset($data['intensiv_price']) !== '') { | |
array_push($args['tax_query'], array( | |
'taxonomy'=>'price', | |
'terms' => array($data['intensiv_price']) | |
)); | |
} | |
// pre_data($args); | |
$custom_filter = new WP_Query($args); | |
if ( $custom_filter->have_posts() ) : | |
/* Start the Loop */ | |
while ( $custom_filter->have_posts() ) : | |
$custom_filter->the_post(); | |
the_title(); | |
endwhile; | |
else : | |
echo "no find posts"; | |
endif; | |
} // end function filter_deals_example($data) | |
// ********************************* HTML ********************************// | |
<div class="q-search-wrap"> | |
<form method="post" action="<?php echo home_url("/deals/"); ?>"> | |
<?php $current_location = get_terms(array('taxonomy' => 'location', 'hide_empty' => true)); ?> | |
<select id="location" name="intensiv_location"> | |
<?php foreach($current_location as $location) { ?> | |
<option value="<?php echo $location->term_id;?>"> | |
<?php echo $location->name; ?> | |
</option> | |
<?php } ?> | |
</select> | |
<?php $current_type = get_terms(array('taxonomy' => 'type', 'hide_empty' => true));?> | |
<select id="type" name="intensiv_type"> | |
<?php foreach($current_type as $type) { ?> | |
<option value="<?php echo $type->term_id;?>"> | |
<?php echo $type->name; ?> | |
</option> | |
<?php } ?> | |
</select> | |
<?php $current_price = get_terms(array('taxonomy' => 'price', 'hide_empty' => true));?> | |
<select id="coast" name="intensiv_price"> | |
<?php foreach($current_price as $price){?> | |
<option value="<?php echo $price->term_id; ?>"><?php echo $price->name; ?></option> | |
<?php } ?> | |
</select> | |
<button class="btn btn-yellow">quick Search</button> | |
</form> | |
</div> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment