• The following is a section of my loop dealing with outputting all posts posted in the selected month. But at present my final foreach loop is outputting ALL posts under the months. Can anybody tell me what I’m doing wrong please? (sorry for the weird formatting, I’m not sure what’s going on there, I pasted the code in then indented it.)

    $months = $wpdb->get_col(“SELECT DISTINCT MONTH(post_date)
    FROM $wpdb->posts
    WHERE post_status = ‘publish’
    AND post_type = ‘post’
    AND YEAR(post_date) = ‘”.$year.”‘
    ORDER BY post_date DESC”);

    foreach($months as $month) :
    ?>

    • <?php echo date( ‘F’, mktime(0, 0, 0, $month) );?>
      <?php $args = array(
      ‘posts_per_page’ => 10,
      ‘offset’ => 0,
      ‘category’ => ”,
      ‘orderby’ => ‘post_date’,
      ‘post_date’ => ‘\” . $month . ‘\”,
      ‘order’ => ‘DESC’,
      ‘include’ => ”,
      ‘exclude’ => ”,
      ‘meta_key’ => ”,
      ‘meta_value’ => ”,
      ‘post_type’ => ‘post’,
      ‘post_mime_type’ => ”,
      ‘post_parent’ => ”,
      ‘post_status’ => ‘publish’,
      ‘suppress_filters’ => true );
      ?>

      <ul class=”archive-posts”>
      <?php

      $myposts = get_posts( $args );
      foreach($myposts as $post) :
      ?>

    • “><?php the_title(); ?>
    • <?php endforeach; ?>

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Trouble outputting the selected month's posts’ is closed to new replies.