Custom search filters between 2 dates
-
Hi everybody,
I’m developing a WordPress Theme and I created a pages that shows a category of posts with a search filter on top of that page.
The search filter should give the possibility the visitors to show posts between 2 dates.
For this, I included in the page the main search form and I modified it like this:<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>news-press-release/"> <label for="s" class="assistive-text">DATE SEARCH</label> <input type="text" class="field" name="s" id="s" placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" /> <label for="from_day" class="from">from</label> <select name="from_day"> <option>DD</option> <option>1</option> <option>2</option> ... </select> <select name="from_month"> <option>MM</option> <option>1</option> <option>2</option> ... </select> <select name="from_year"> <option>YY</option> <option>2012</option> <option>2013</option> </select> <label for="to_day" class="from">to</label> <select name="to_day"> <option>DD</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> ... </select> <select name="to_month"> <option>MM</option> <option>1</option> <option>2</option> ... </select> <select name="to_year"> <option>YY</option> <option>2012</option> <option>2013</option> </select> <input type="submit" class="submit" name="submit" id="searchsubmit" value="Go" /> </form>
As you can see, the form is redirecting to the same page I use to show the posts.
To show the posts, I use this code in the template page:<?php query_posts('category_name=news&posts_per_page=10&order=ASC'); ?> <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID();?>"> <p class="postmetadata"> <?php the_time('j F Y') ?> </p> <p class="news_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> <?php the_excerpt(); ?> </div><!--end post--> <?php endwhile; ?> <?php endif; ?>
I tried to add a where filter the before the loop but it always shows me the same posts list whatever the date I choose.
Does anybody have an idea of what I made wrong ?
Thank you
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom search filters between 2 dates’ is closed to new replies.