• Jeveloper

    (@jeveloper)


    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 get redirected to index.php where I have the loop and it display “no posts…” while it should display “No posts…” on the archive page, 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?

The topic ‘WP_query issue with no posts’ is closed to new replies.