Support » Fixing WordPress » Past moth’s posts not showing?

  • I have an odd problem after upgrading to 1.0. As you can see on my site, on the sidebar there are plenty of archived months. However, clicking on any of those months shows no posts. Looking at the MySQL database, all past posts are still there. What’s strange is that I haven’t added any posts this month since I upgraded, yet WP seems to display this month’s posts fine.
    Any idea why it would list the months as having posts, yet not show any posts?

Viewing 4 replies - 1 through 4 (of 4 total)
  • OK, I somewhat figured out what’s going on. The query is tacking on the current year for every query for some reason.
    Here’s an example of a query when I uncomment line #319 in wp-blog-header.php:
    SELECT DISTINCT * FROM b2posts WHERE 1=1 AND YEAR(post_date)=2003 AND MONTH(post_date)=10 AND YEAR(post_date)=2004 AND post_date <= ‘2004-01-13 14:09:46’ AND (post_status = “publish”) ORDER BY post_date DESC
    Note the presence of two “YEAR(post_date)”, one being the current year! Digging further:
    wp-blog-header.php, line 68-87:

    if ($m != ”) {
    $m = ”.intval($m);
    $where .= ‘ AND YEAR(post_date)=’.substr($m,0,4);
    if (strlen($m)>5)
    $where .= ‘ AND MONTH(post_date)=’.substr($m,4,2);
    if (strlen($m)>7)
    $where .= ‘ AND DAYOFMONTH(post_date)=’.substr($m,6,2);
    if (strlen($m)>9)
    $where .= ‘ AND HOUR(post_date)=’.substr($m,8,2);
    if (strlen($m)>11)
    $where .= ‘ AND MINUTE(post_date)=’.substr($m,10,2);
    if (strlen($m)>13)
    $where .= ‘ AND SECOND(post_date)=’.substr($m,12,2);
    }
    if ($year != ”) {
    $year = ” . intval($year);
    $where .= ‘ AND YEAR(post_date)=’ . $year;
    }

    OK, so where is $year set initially? If I comment out lines 84 & 87, archives work fine. I need $year to be initially empty it seems, and it’s not. Ideas?

    OK fixed it, at least for me. Changed lines 68-85 in wp-blog-header.php to:
    if ($m != ”) {
    $m = ”.intval($m);
    $where .= ‘ AND YEAR(post_date)=’.substr($m,0,4);
    if (strlen($m)>5)
    $where .= ‘ AND MONTH(post_date)=’.substr($m,4,2);
    if (strlen($m)>7)
    $where .= ‘ AND DAYOFMONTH(post_date)=’.substr($m,6,2);
    if (strlen($m)>9)
    $where .= ‘ AND HOUR(post_date)=’.substr($m,8,2);
    if (strlen($m)>11)
    $where .= ‘ AND MINUTE(post_date)=’.substr($m,10,2);
    if (strlen($m)>13)
    $where .= ‘ AND SECOND(post_date)=’.substr($m,12,2);
    } elseif ($year != ”) {
    $year = ” . intval($year);
    $where .= ‘ AND YEAR(post_date)=’ . $year;
    }

    OK, that wasn’t quite right. Here’s what seems to really work now:
    if ($m != ”) {
    $m = ”.intval($m);
    $where .= ‘ AND YEAR(post_date)=’.substr($m,0,4);
    if (strlen($m)>5)
    $where .= ‘ AND MONTH(post_date)=’.substr($m,4,2);
    if (strlen($m)>7)
    $where .= ‘ AND DAYOFMONTH(post_date)=’.substr($m,6,2);
    if (strlen($m)>9)
    $where .= ‘ AND HOUR(post_date)=’.substr($m,8,2);
    if (strlen($m)>11)
    $where .= ‘ AND MINUTE(post_date)=’.substr($m,10,2);
    if (strlen($m)>13)
    $where .= ‘ AND SECOND(post_date)=’.substr($m,12,2);
    }
    if ($year != ”) {
    $year = ” . intval($year);
    $year = substr($m,0,4);
    }

    Err.. forgot to comment out:
    //$year = ” . intval($year);

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Past moth’s posts not showing?’ is closed to new replies.