• Hi, i just upgrade my wp from 2.2.1 to 2.3 and i got this error message before my title
    “Warning: array_key_exists(): The first argument should be either a string or an integer in /home/llyod/public_html/wp-includes/category-template.php on line 176”

    Please help me resolve these problems.
    Thanks!

Viewing 15 replies - 1 through 15 (of 20 total)
  • Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in blah/blah/blah/wp-includes/category-template.php on line 176

    Now I did some research and apparently there is a line in a file called wp-includes/category-template.php.

    That line says

    if(array_key_exists($category, $categories))

    What it should say is

    if(array_key_exists(’$category’, $categories))

    [with the little quotes]

    Please let me know if that works.

    I have the same exact problem. I tried what you recommended … it didnt work, it made my site completely inaccessible. Do you have any other ideas, because I really want this code gone. Thanks.

    bfree74: I guess you are responding to my post. I have no idea why it didn’t work and made your site inaccessible.
    I hope llyod will respond and see if it helped.

    You did use the ‘ (apostrophe) rather than a single curly quote mark right?

    I upgraded my theme and all is well

    bfree74, what did you change to make the site accessible?

    yarflys

    (@yarflys)

    For what it is worth, I was having the same problem as Lloyd and MVanPatten’s advice worked perfectly. Thanks!

    This is apparently the fix:

    This is the original code:

    —————————————————————
    function in_category( $category ) { // Check if the current post is in the given category
    global $post, $blog_id;

    $categories = get_object_term_cache($post->ID, ‘category’);
    if ( false === $categories )
    $categories = wp_get_object_terms($post->ID, ‘category’);
    if(array_key_exists($category, $categories))
    return true;
    else
    return false;
    }
    ——————————————————
    This is the fix:
    ———————————————————-
    function in_category( $category ) { // Check if the current post is in the given category
    global $post, $blog_id;

    $categories = get_object_term_cache($post->ID, ‘category’);
    if ( false == $categories )
    $categories = wp_get_object_terms($post->ID, ‘category’);
    if(array_key_exists(‘category’, $categories))
    return true;
    else
    return false;
    }
    ———————————————————-
    Notice the === signs. I changed that to ==

    I also changed $category to ‘category’
    ———————————————————-
    See if that works for you. I am no longer getting the error message, but let’s see if that fixews the problem for everybody

    I was also having the same problem as Lloyd and yarflys. MVanPatten’s advice worked. Simply added ‘ (apostrophes) around $category of the if(array_key_exists($category, $categories)) entry.

    Thanks!

    Thanks for the fix, farseas. It worked like a gem.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Ummm… I can’t believe nobody noticed this, but that fix above is NOT a correct fix. That change will simply break the in_category function. If your theme uses that function, then your theme won’t work properly.

    The original code is perfectly correct and does not need to be modified at all. The problem is that somewhere your theme has a call to in_category that is wrong. in_category requires a parameter of the category that it’s checking.

    Search your theme for “in_category”. Likely it’s using the function wrong. Take it up with the theme author. Do NOT change the core code in category_template.php, because the core code is not where the problem is.

    If it’s called wrong, and since this is very common (I experienced it myself with a theme), then WordPress should give a proper custom PHP notice instead of a built-in PHP warning (that really doesn’t pinpoint the problem at all!)

    It’s just a coincidence that I can find this support thread.

    My advice is that if the argument isn’t an int or integer, then WordPress should generate a low-priority notice and proceed (returning false). In this way, end-users won’t be surprised (negatively) yet theme developers still know their themes are broken (because they should turn on PHP notices).

    Hopefully this problem gets resolved quickly.

    By the way, if anyone is interested, this is my “fix”:

    (added around line 176)

    ...
            if ( false === $categories )
                    $categories = wp_get_object_terms($post->ID, 'category');

    if (!is_string($category) && !is_int($category))
    return false;

    if(array_key_exists($category, $categories))
                    return true;
            else
    ...

    You know, after trying hard to make the above comment look right, I wonder why all markups always mess up the text.

    Any markup always modifies what I edit in some way, not just the displayed text but also the editable text.

    1. Submit something
    2. It doesn’t look right, click Edit and immediately submit it
    3. It looks even worse

    It doesn’t feel right when editing nothing can change the content. It’s like pushing the “Save” button has a side effect of re-reformatting your whole page (i.e. the previous reformatting and the next reformatting has different results), even though you made no changes at all.

    please use the latest version of the theme, downloadable from the site wpthemepark.com.
    I already fixed it in the theme .

    If it happens to be a bug in one of my themes [https://themes.sadish.net], please use the latest version from the corresponding theme page. If it is still not fixed, use the contact form at https://sadish.net and let me know.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Category-template.php problem after upgrade to 2.3’ is closed to new replies.