Hi I am trying to create a form that filters my posts by 3 requirements, Categories, Author and Date. The user should be able to select a requirement from each dropdown (or leave empty for all) and get an outcoem based on that, so for example be able to select HMTL(from categories), Joe Bloggs(from Author) and February 2017(from date) and get a page that show all posts in the HTMl, written by Joe Bloggs, published in Feb 2017.
So far I have some functions and a form, which when selecting a category and author (no date) appears to work and directs me to news/category/news/?user=1&date-dd&submit=filter which shows what I want.
However the date is where problems start. If I select the same category and author as previous but then select January 2017 I get the URL news/category/news/?user=1&date-dd=http%3A%2F%2Flocalhost%2Fbrandbiology%2Fnews%2F2017%2F01%2F&submit=filter which now doesnt work, it will show the category and author but no date and a weird url.
Secondaly if I just put <?php wp_get_archives( $args ); ?>
on my page, it will display a list of dates within an <li>
(not what I want but I did it for testing) and click January 2017 in that it will take me to news/2017/01/ which will display only posts in January (doesnt work with category IE news/category/blog/2017/01/ - shows 404).
My questions therefore is trying to create the right outcome that will display the posts based on the 3 requirements I want.
Thanks in Advance
Here is my Functions:
function get_cat_droplist(){
$args = array(
'show_option_all' => 'All Categories',
'show_option_none' => '',
'option_none_value' => '-1',
'orderby' => 'ID',
'order' => 'ASC',
'show_count' => 1,
'hide_empty' => 1,
'child_of' => 0,
'exclude' => '',
'include' => '',
'echo' => 1,
'selected' => 0,
'hierarchical' => 0,
'name' => 'cat',
'id' => '',
'class' => 'postform',
'depth' => 0,
'tab_index' => 0,
'taxonomy' => 'category',
'hide_if_empty' => true,
'value_field' => 'term_id',
);
$output = wp_dropdown_categories( $args );
}
function get_author_droplist(){
$args = array(
'show_option_all' => 'All Author', // string
'show_option_none' => null, // string
'hide_if_only_one_author' => true, // string
'orderby' => 'display_name',
'order' => 'ASC',
'include' => null, // string
'exclude' => null, // string
'multi' => false,
'show' => 'display_name',
'echo' => true,
'selected' => false,
'include_selected' => false,
'name' => 'user', // string
'id' => null, // integer
'class' => null, // string
'blog_id' => $GLOBALS['blog_id'],
'who' => null // string
);
$output = wp_dropdown_users( $args );
}
function get_date_droplist(){
$args = array(
'type' => 'monthly',
'limit' => '',
'format' => 'option',
'before' => '',
'after' => '',
'show_post_count' => true,
'echo' => 0,
'order' => 'DESC',
'post_type' => 'post'
);
$output = wp_get_archives( $args );
}
and my HTML/PHP
<form action="<?php bloginfo('url'); ?>" method="get">
<div>
<span class="cat-list-header text-color-1">Filter posts:</span>
<?php
$select = get_cat_droplist();
echo $select;
?>
<?php
$select = get_author_droplist();
echo $select;
?>
<select name="date-dd">
<option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
<?php wp_get_archives( array( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?>
</select>
<input type="submit" name="submit" value="filter" /> <!--CHANGE VALUE TO YOUR LIKING!-->
</div>
</form>