• How would I display all the posts that have been posted in that current month?

    I’m trying to use “wp_get_archives” to do it but with no success, I know this is probably a really easy for one of you WordPress wizards.

    All help much appreciated.

    Terry

Viewing 7 replies - 1 through 7 (of 7 total)
  • http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters

    <?php $today = getdate();
    $this_month = new WP_Query( array( 'posts_per_page' => -1, 'year' => $today["year"], 'monthnum' => $today["mon"]) );
    if( $this_month->have_posts() ) : while( $this_month->have_posts() ) : $this_month->the_post();
    /*whatever you want to output*/
    endwhile;
    else : echo 'no posts this month';
    endif; wp_reset_postdata(); ?>

    http://codex.wordpress.org/Class_Reference/WP_Query#Time_Parameters

    Thread Starter tilleyt88

    (@tilleyt88)

    ok its kinda worked.

    If there isn’t a post for that month it comes up with ‘no posts this month’ but when there is a post for the month it just comes up blank… what am I missing?

    what coding have you put instead of this spaceholder:

    /*whatever you want to output*/

    Thread Starter tilleyt88

    (@tilleyt88)

    well went on to the link you posted and put in the code

    // Create a new filtering function that will add our where clause to the query
    function filter_where( $where = '' ) {
    	// posts in the last 30 days
    	$where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
    	return $where;
    }
    
    add_filter( 'posts_where', 'filter_where' );
    $query = new WP_Query( $query_string );
    remove_filter( 'posts_where', 'filter_where' );

    but doesn’t show anything

    Thread Starter tilleyt88

    (@tilleyt88)

    I just want to show a list of post that have been posted in the current month.

    went on to the link you posted and put in the code

    fine;
    I also posted some direct code which is not using the filter – have you tried that?

    if you are using your last posted code, do you have a loop added after what you showed here?

    just this alone:

    $query = new WP_Query( $query_string );

    does of course not show anything.

    Thread Starter tilleyt88

    (@tilleyt88)

    no I don’t think so… its getting a bit confusing for me I must admit.

    here is the the whole page of code if this helps

    and here is the actual page

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How do I display a list of posts from the current month?’ is closed to new replies.