WordPress.org

Ready to get started?Download WordPress

Forums

Category-template.php problem after upgrade to 2.3 (21 posts)

  1. llyod
    Member
    Posted 6 years ago #

    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!

  2. mvanpatten
    Member
    Posted 6 years ago #

    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.

  3. bfree74
    Member
    Posted 6 years ago #

    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.

  4. mvanpatten
    Member
    Posted 6 years ago #

    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?

  5. bfree74
    Member
    Posted 6 years ago #

    I upgraded my theme and all is well

  6. mvanpatten
    Member
    Posted 6 years ago #

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

  7. yarflys
    Member
    Posted 6 years ago #

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

  8. farseas
    Member
    Posted 6 years ago #

    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

  9. nadooh
    Member
    Posted 6 years ago #

    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!

  10. nicolerork
    Member
    Posted 6 years ago #

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

  11. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  12. ceefour
    Member
    Posted 6 years ago #

    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.

  13. ceefour
    Member
    Posted 6 years ago #

    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
    ...
  14. ceefour
    Member
    Posted 6 years ago #

    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.

  15. sadish
    Member
    Posted 6 years ago #

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

  16. sadish
    Member
    Posted 6 years ago #

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

  17. Megagents
    Member
    Posted 6 years ago #

    Anyone know how to get rid of this?

  18. whooami
    Member
    Posted 6 years ago #

    searching isnt your strong point apparantly. duplicate posts are though.

    http://wordpress.org/support/topic/135658?replies=13

    Read. Dont post. Read.

  19. Jeff1701
    Member
    Posted 6 years ago #

    Ceefour, your solution worked for me. Thanks!

  20. metoo55
    Member
    Posted 6 years ago #

    Ceefour, your solution worked for me too :D. Thank you very much.

  21. 10acne
    Member
    Posted 6 years ago #

    I upgraded my theme :)

Topic Closed

This topic has been closed to new replies.

About this Topic