WordPress.org

Ready to get started?Download WordPress

Forums

can't see why 'monthnum' parameter being ignored (3 posts)

  1. Skeary
    Member
    Posted 1 year ago #

    I'm dynamically building a query into a variable called $qstring and then executing it

    When it looks like: post_type=post&posts_per_page=4&order_by=modified&monthnum =12&year=2012&offset=8 it pulls back everything from 2012, rather than just December.

    Is there something amiss with my query formatting? It is in an ajax call so nothing else should be interfering with it... or?

    Really at a loss as to how this would not be working.

    The whole function looks like this:

    function load_more(){
        $offset = $_REQUEST['offset'];
    
        $qstring = 'post_type=post&posts_per_page=4&order_by=modified';
    
        if (isset($_REQUEST['cat'])){ $qstring .= '&cat='.$_REQUEST['cat'];}
        if (isset($_REQUEST['tag'])){ $qstring .= '&tag_id='.$_REQUEST['tag'];}
        if (isset($_REQUEST['month'])){ $qstring .= '&monthnum ='.$_REQUEST['month'];}
        if (isset($_REQUEST['year'])){ $qstring .= '&year='.$_REQUEST['year'];}
    
        $qstring .= '&offset='.$offset;
        echo '<div>';
        // echo '<p>'.$qstring.'</p>';
        $query = new WP_Query( $qstring );
        $result = null;
        while ( $query->have_posts() ) {
            $query->the_post();
            my_print_post();
        }
        echo '</div>';
        exit();
    }
  2. bcworkz
    Member
    Posted 1 year ago #

    Just a guess, try removing the space after monthnum. You'd think the query parser would ignore spaces, but maybe not.

  3. Skeary
    Member
    Posted 1 year ago #

    That did it, thanks! Didn't notice it snuck in there..

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.