<?php
session_start();
if(isset($_POST['search'])){
$_SESSION['country']=$_POST['country'];
$_SESSION['work']=$_POST['work'];
}
if(isset($_POST['reset'])){
if(isset($_SESSION['country'])){
unset($_SESSION['country']);
}
if(isset($_SESSION['work'])){
unset($_SESSION['work']);
}
}
/* Template Name: custom Chain*/
get_header();
?>
<section id="container">
<?php if(!is_home() && !is_front_page() && get_option('afl_breadcrumbs_enable') == 'open'):?>
<!--breadcrumbs -->
<section class="container">
<div class="container breadcrumbs">
<div class="page-header">
<h1><?php the_title();?></h1>
<div><?php echo get_option('breadcrumbs_text'); ?><a href="<?php echo home_url(); ?>"><?php echo BREADCRUMBS_HOME_TEXT ?></a><?php echo BREADCRUMBS_DIVIDER ?><?php the_title();?></div>
</div>
</div>
</section>
<?php endif; ?>
<div class="container">
<div class="row-fluid">
<?php
$args = array(
'child_of' => 59,
'hide_empty' => 0
);
$categories=get_categories($args);
?>
<form action="" method="post">
<div style="float: left; min-width: 25%">
<label>Area</label>
<select name="zone" onchange="this.form.submit()">
<option value="59">Tutte</option>
<?php
foreach($categories as $category) {
if($category->parent == 59 ){ ?>
<option value="<?php echo $category->term_id; ?>" <?php if($_POST['zone'] == $category->term_id){ ?> selected <?php } ?> ><?php echo $category->name; ?></option>
<?php
}
}
?></select>
</div>
<?php if(isset($_POST["zone"])) {
$args = array(
'child_of' => $_POST["zone"],
'hide_empty' => 0
); }
else {
$args = array(
'child_of' => 59,
'hide_empty' => 0
);
}
$categories=get_categories($args);
?>
<div style="float: left; min-width: 25%">
<label>Paese</label>
<select name="country" >
<option value="<?php if(isset($_POST["zone"])){echo $_POST["zone"];} else echo"59"; ?>">Tutti</option>
<?php
foreach($categories as $category) {
if($category->parent != 59 ){ ?>
<option value="<?php echo $category->term_id; ?>" <?php if($_POST['country'] == $category->term_id){ ?> selected <?php } ?>>
<?php echo $category->name; ?></option>
<?php
}
}
?></select>
</div>
<?php ?>
<?php
$args = array(
'child_of' => 65,
'hide_empty' => 0
);
$categories=get_categories($args);
?>
<div style="float: left; min-width: 25%">
<label>Settore</label>
<select name="industry" onchange="this.form.submit()">
<option value="65">Tutti</option>
<?php
foreach($categories as $category) {
if($category->parent == 65 ){ ?>
<option value="<?php echo $category->term_id; ?>" <?php if($_POST['industry'] == $category->term_id){ ?> selected <?php } ?> > <?php echo $category->name; ?></option>
<?php
}
}
?></select>
</div>
<?php if(isset($_POST["industry"])) {
$args = array(
'child_of' => $_POST["industry"],
'hide_empty' => 0
);
}
else {
$args = array(
'child_of' => 65,
'hide_empty' => 0
);
}
$categories=get_categories($args);
?>
<div style="float: left; min-width: 25%">
<label>Prodotto</label>
<select name="work" >
<option value="<?php if(isset($_POST["zone"])){ echo $_POST["industry"];} else echo "65"; ?>">Tutti</option>
<?php
foreach($categories as $category) {
if($category->parent != 65 ){
?>
<option value="<?php echo $category->term_id; ?>" <?php if($_POST['work'] == $category->term_id){ ?> selected <?php } ?>><?php echo $category->name; ?></option>
<?php
}
}
?></select>
</div>
<?php ?>
<div class="row-fluid">
<p style="float: left; min-width:50%"><input type="submit" name="search" value="Cerca" ></p>
</form>
<form action="" method="post">
<p style="float: left; min-width:50%"><input type="submit" name="reset" value="Reset"></p>
</form>
</div>
<hr />
<?php
if(isset($_SESSION['country'])){
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$category_posts = new WP_Query(array( 'category__and' => array( $_SESSION['country'], $_SESSION['work'] ),'posts_per_page' => '20','paged' => $paged ));
?>
<div class="custom-search-content">
<?php
if($category_posts->have_posts()) :
while($category_posts->have_posts()) :
$category_posts->the_post();
?>
<!--
<h1><a href="<?php the_permalink(); ?>" ><?php the_title() ?></a></h1>
<div class="custom-search-excerpt">
<?php the_excerpt() ?>
</div>
-->
<article class="blog-post <?php echo get_post_class() ?>" id="post-<?php the_ID(); ?> ">
<?php $src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'full');?>
<?php if (has_post_thumbnail()) { ?>
<a href="<?php echo $src[0] ?>" rel="prettyPhoto" title="<?php echo $post->post_title ?>"><?php the_post_thumbnail('single'); ?></a>
<?php } ?>
<div class="row-fluid">
<div class="span3"><?php include(TEMPLATEPATH . '/inc/blog-info.php'); ?></div>
<div class="span9">
<h2 class="post-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?><span class="read_more"><a href="<?php the_permalink(); ?>">[ Leggi Tutto → ]</a></span>
</div>
</div>
</article>
<hr />
<?php
endwhile; ?>
</div>
<nav class="custom-search-nav">
<div style="float: left; font-size: 16px;"><?php previous_posts_link( '« PRECEDENTE', $category_posts->min_num_pages) ?></div>
<div style="float: right; font-size: 16px;"><?php next_posts_link( 'SUCCESSIVO »', $category_posts->max_num_pages) ?></div>
</nav>
<?php
else:
?>
Nessun post appartiene all'insieme di categorie selezionate.
<?php
endif;
}
?>
</div>
</div>
</section>
<?php get_footer(); ?>
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Open in new window
Because the form is using sessions, which I assume are being set when the form is submitted, you would simply add an else clause to the above to handle the instance when the session is not set:
Open in new window
When the page loads, there is no session data yet so the Loop is not initialized. By adding a new condition that feeds something to the Loop at any state, it should load data. Documentation on feeding arguments to the loop is here:
http://codex.wordpress.org/Class_Reference/WP_Query