Forums

Past moth's posts not showing? (5 posts)

  1. gudlyf
    Member
    Posted 8 years ago #

    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?

  2. gudlyf
    Member
    Posted 8 years ago #

    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?

  3. gudlyf
    Member
    Posted 8 years ago #

    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;
    }

  4. gudlyf
    Member
    Posted 8 years ago #

    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);
    }

  5. gudlyf
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.