WordPress.org

Ready to get started?Download WordPress

Forums

PHP error in wp-blog-header.php (9 posts)

  1. araneo
    Member
    Posted 10 years ago #

    I am getting the following error message in my test installation of version 1.0.1 at http://www.web-ho.com/Blog/wordpress-1.0.1-miles/
    Warning: Invalid argument supplied for foreach() in ...wordpress-1.0.1-miles/wp-blog-header.php on line 337
    Thing is, wp-blog-header.php has only 323 lines!
    Because of that error, the array "$categories" becomes undefined in the function the_category().

  2. araneo
    Member
    Posted 10 years ago #

    That's where the error for $categories occurs: the line in question is
    foreach ($categories as $category) {
    I commented the function out and the original error in wp-blog-header.php remains

  3. philor
    Member
    Posted 10 years ago #

    Only 323 lines? If you're sure, that might be part of the problem, since I just grabbed a fresh copy, and it should be 363 lines long, with line 337 being a foreach that assumes a call to the database asking for post categories was successful. What version were you upgrading from, and did upgrade.php seem happy about what it did?

  4. araneo
    Member
    Posted 10 years ago #

    It's not an upgrade, it is a fresh installation (I populated the new posts and comments tables manually from the existing 0.71 version that's running on the site).
    The file does not appear truncated, it ends with the following:
    if (1 == count($posts)) {
    if ($p || $name) {
    $more = 1;
    $c = 1;
    $single = 1;
    }
    if ($s && empty($paged)) { // If they were doing a search and got one result
    header('Location: ' . get_permalink($posts[0]->ID));
    }
    }
    }
    ?>
    (lines 312 to 323 according to my text editor).
    I put a copy of it as wp-blog-header.txt. Can somebody check to see if it is correct?
    Thanks.

  5. philor
    Member
    Posted 10 years ago #

    Ah, just a disagreement about what counts as a line - your editor must not count blank lines. Anyway, what's failing is
    $dogs = $wpdb->get_results("SELECT DISTINCT
    ID, category_id, cat_name, category_nicename, category_description
    FROM $tablecategories, $tablepost2cat, $tableposts
    WHERE category_id = cat_ID AND post_id = ID AND post_id IN ($post_id_list)");

    So my guess would be that it doesn't like something in the way you populated the category-related data, and for a wild guess based on what the upgrade script would have done if you had done an upgrade, I'd think maybe the category_nicename?

  6. araneo
    Member
    Posted 10 years ago #

    The categories table was created the regular way, using wp-admin, before posts and comments were copied from the old tables. I made sure that the cat_ID and cat_name were identical and in the same order in both tables, and the new fields category_nicename, category_description and category_parent (what is that?) were filled in properly by the script.
    But in the SQL query I notice they talk about "category_id" while my table contains a field called " cat_ID" instead. Is that the problem?

  7. araneo
    Member
    Posted 10 years ago #

    Another hint: when I look at the categories with wp-admin/categories.php they are listed as they should except that the number of posts in each category is wrong: only the default shows 1, presumably the test post created by the installation, while the other two categories show zero. I looked at wp_posts with phpMyAdmin and the post_category column is properly filled with the correct category number for each post.

  8. philor
    Member
    Posted 10 years ago #

    Ah, gotcha, finally. You'd think someone who actually knows WP would have stepped in before now ;)
    wp_posts.post_category doesn't mean anything, now that posts can have multiple categories. And category_id is wp_post2cat.category_id, a column in the post2cat table, not wp_categories.cat_ID, a column in the categories table.
    Say you have a post, #75, that's in category #7. The connection isn't made by wp_posts.post_category being 7, because that only allows for one category. So you have a row in the wp_post2cat table, where rel_id is just an id for that row, and wp_post2cat.post_id is 75 and wp_post2cat.category_id is 7. If it's in category #7 and category #9, you have two rows in wp_post2cat, both with post_id = 75, and one with each category_id.

  9. araneo
    Member
    Posted 10 years ago #

    That's it! wp_post2cat was bad. I refilled it from the data in b2posts (since each legacy post had only one category, it was a one to one update, very easy.) It seems to be working now; back to customization.
    Thanks to all for the help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.