I am using form for my archive page so user can specify which posts they want to see and how they want to see them. I have it setup so they can choose ascending or descending order, posts per page etc, using $_GET in my forms. However I have also set up form to set display posts by year/month:
<select name="monthnum"> <option value="null">Month</option> <option value="1">January</option> <option value="2">February</option> <option value="3">March</option>
etc. for all month and the same one for year
then my query arguments look like this:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $custom_args = array( 'post_type' => 'post', 'posts_per_page' => $_GET["posts-per-page"], 'paged' => $paged, 'order' => $_GET["order"], "orderby" => "date", "year" => $_GET["year"], "monthnum" => $_GET["monthnum"] ); $custom_query = new WP_Query( $custom_args );
So far I added a couple of posts to test things so they are all august 2015 and if i set these through $_GET, it displays well however if I try to do January or any other month apart from August, my archive page gets redirected to the page with the loop which is index.php in my case and it display "no posts..." while it should stay on the same page and display "No posts..." on it. as I've set it up. There's no need to post rest of the code since I've figured out that the redirection happens immediately after new WP_query is created. What might cause this issue? Again $_GET ["posts per page"] and $_GET["order"] all work as expected.