WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Found 1 bug. Need help w/2nd. (6 posts)

  1. palyne
    Member
    Posted 6 years ago #

    I'm using Blog Oh Blog theme. I updated an ancient (many versions ago) WP install to 2.2. I deactivated all plugins first.

    the sidebar categories line in this theme is:
    <?php wp_list_categories('show_count=1&title_li=<h2>Categories</h2>'); ?>
    which should work by default with WordPress.

    I found one bug here:

    links.php

    line 293 dealing with cat_name refers to name instead of cat_name
    changed this and it solved one visible problem.

    However the blog is still throwing the second error. The code that WP is taking exception to has the same issue, 'name' instead of 'cat_name'. The thrown code is:

    WordPress database error: [Unknown column 'name' in 'order clause']
    SELECT * FROM wp_categories WHERE cat_ID > 0 AND link_count > 0 ORDER BY name ASC

    I did find this issue of 'name' instead of 'cat_name' in other places where it seemed to also be a bug:

    links.php

    line 526 dealing with cat_name refers to name instead of cat_name
    changed this and no visible fix occurred.

    template_functions_category.php

    line 122 dealing with cat_name refers to $cat instead of $cat_name
    changed this and no visible fix occurred.

    category.php

    line 22 dealing with category refers to 'name' instead of 'cat_name'
    changed this and no visible fix occurred.
    changed it back because I'm not sure that was wrong. Because:

    There are MANY references to only $name or 'name' because this is used for
    (a) the parent of the present category is made into a var called 'name' it seems like
    (b) the var 'name' is also used in post functions and other unrelated-to-category stuff
    (c) there are many places where it sets 'cat_' and then appends either 'ID' or 'name' to that apparently

    I do not program in PHP. Needless to say, fixing my now-broken categories sidebar that was working perfectly until I upgraded is hard for me since most of what I'm looking at is greek to me.

    I found a lot of code I manually waded through that had one of the key elements of the code still throwing an error. But I can't find the second bug. The thing I changed in that wp-includes links.php file did solve one visible error that was being thrown. But I cannot seem to find the source of the other error. I would greatly appreciate any assistance.

    Surely other people are encountering this problem!

    PJ

  2. palyne
    Member
    Posted 6 years ago #

    Um, this forum ate the code that I pasted in to example what is still being thrown as an error. Here is it entered again with line returns as it seems like it is just not showing it past the right side margin:

    SELECT * FROM wp_categories
    WHERE cat_ID > 0
    AND link_count > 0
    ORDER BY name ASC
  3. palyne
    Member
    Posted 6 years ago #

    This was solved.

    In the theme "Blog Oh Blog" it had a line just below categories that read:

    <?php wp_list_bookmarks(); ?>

    That is what was throwing the error. I'm sure it's a bug that needs fixing, but for my purposes, just taking the line of code out works for me.

  4. moshu
    Member
    Posted 6 years ago #

    If it's a bug, it is in your theme.
    Actually, the line you have deleted should be the correct template tag to be used with version 2.2.2 - if you updated to the latest.
    See the deprecated and newly introduced template tags:
    http://codex.wordpress.org/Template_Tags

  5. MirandMS
    Member
    Posted 6 years ago #

    We encountered this error and isolated the problem.

    This is due to a bug in older versions of PHP.

    parse_str() advertises that it will store variables in an array if an array is passed as the optional second parameter, INSTEAD of creating the variables in the current scope.

    What we actually observed was that it created the array AS WELL AS creating the variables in the current scope.

    This behavior causes the extract() call (with EXTR_SKIP) to NOT create the orderby variable because, due to the bug in parse_str() it already exists, and because EXTR_SKIP is specified, extract WILL NOT overwrite the value in the orderby variable.

    Here is some code that exposes the problem:

    <pre>
    <?
    $args = "type=link&orderby=name&order=ASC&hierarchical=0";
    echo "Test string \$args = \"$args\"\n";
    echo "\$orderby before call to parse_str() = $orderby\n";
    echo "Calling parse_str(\"$args\", \$arr)\n";
    parse_str($args, $arr);
    echo "\$orderby after call to parse_str() = $orderby\n";
    echo "\$arr = "; print_r ($arr); echo "\n\nAdd prefix to a value in \$arr array\n";
    $arr['orderby'] = "cat_" . $arr['orderby'];
    echo "\$arr = "; print_r ($arr); echo "\n\nCall extract(\$arr, EXTR_SKIP)\n";
    extract($arr, EXTR_SKIP);
    echo "\$arr = "; print_r ($arr); echo "\n";
    echo "orderby after call to extract(\$arr, EXTR_SKIP) = $orderby\n";
    ?>
    </pre>

    NOTE: This bug has been fixed in later versions of PHP, so depending upon the version you are running, the code above may execute correctly (meaning parse_str() won't create variables in scope)

    If you are seeing this error:

    [Unknown column 'name' in 'order clause']
    SELECT * FROM wp_categories WHERE cat_ID > 0 AND link_count > 0 ORDER BY name ASC

    then more than likely this is the problem. There are a few simple ways to work around this. We will post a fix later.

  6. MirandMS
    Member
    Posted 6 years ago #

    It might be informative to mention that we found the problem in the function get_categories() in wp-includes/category.php

Topic Closed

This topic has been closed to new replies.

About this Topic