• I am getting the following error message in my test installation of version 1.0.1 at https://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().

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter araneo

    (@araneo)

    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

    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?

    Thread Starter araneo

    (@araneo)

    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.

    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?

    Thread Starter araneo

    (@araneo)

    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?

    Thread Starter araneo

    (@araneo)

    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.

    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.

    Thread Starter araneo

    (@araneo)

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘PHP error in wp-blog-header.php’ is closed to new replies.