Forums

Warning: wp-includes/taxonomy.php on line 2797 (23 posts)

  1. jgrietveld
    Member
    Posted 7 months ago #

    Hi,

    Out of nowhere I have an error in one of my templates on a page where I'm using the WordPress function wp_list_categories() quite a few times.

    The error message is this:

    Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/.../public_html/wp-includes/taxonomy.php on line 2797
    
    Warning: implode() [function.implode]: Invalid arguments passed in /home/.../public_html/wp-includes/taxonomy.php on line 2797
    
    Warning: Invalid argument supplied for foreach() in /home/.../public_html/wp-includes/taxonomy.php on line 2804

    Is anybody familiar with this error message and can tell me how to fix this or at least what could be causing this?

    Many thanks!

    Jerry

  2. Josh
    Member
    Posted 7 months ago #

    There is apparently an error in the way the function is behaving. This could be because of how the function was written, or because it isn't playing "nicely" with what it is calling.

    What is the function you are using?

  3. jgrietveld
    Member
    Posted 7 months ago #

    <?php wp_list_categories('child_of='.get_category_id('A').'&title_li=<h2 class="authors_index">A</h2>&show_count=1&show_option_none=<span class="no_quotes">No quotes</span>'); ?>

    And this for every letter of the alphabet.

  4. jgrietveld
    Member
    Posted 7 months ago #

    And the function for get_category_id() is:

    function get_category_id($cat_name){
    	$term = get_term_by('name', $cat_name, 'category');
    	return $term->term_id;
    }
  5. Josh
    Member
    Posted 7 months ago #

    And this was working up until a certain point?

  6. jgrietveld
    Member
    Posted 7 months ago #

    Yeah, template was finished and in working order just a few days ago. Completely developed on WordPress 3.2.1 so there hasn't been an update in the mean time which could have caused this...

  7. jgrietveld
    Member
    Posted 7 months ago #

    It seems to be a common error at the moment. A search in Google gives 62,300 results.

  8. Josh
    Member
    Posted 7 months ago #

    Gotcha. I'm no programmer. But I was wondering how those five single quotation marks are used. I always thought you had to open AND close when using a single apostrophe.

  9. Josh
    Member
    Posted 7 months ago #

    Nevermind, I see it now. Sorry for the confusion. Still, when using them in the same line... do you not switch between single and double quotations?

  10. jgrietveld
    Member
    Posted 7 months ago #

    It's a mix of PHP and HTML. In PHP single and double quotations have the same function as longs as you use them consistently. HTML only wants double quotations. So the double quotations are for the HTML markup and the single ones for the PHP code.

  11. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Not quite... In WordPress, stick to using single quotes in PHP. And HTML will also accept single quotes quite happily.

  12. Josh
    Member
    Posted 7 months ago #

    Thank you. Well, it seems I'm not going to be of much help to you :\

    So I looked in the core wordpress files at the line giving the error above (in the taxonomy.php) file.

    Any idea how these two are related? And why it's triggering the warning from there?

  13. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Is this a custom function in your theme'#s functions.php file?

    function get_category_id($cat_name){
    	$term = get_term_by('name', $cat_name, 'category');
    	return $term->term_id;
    }

    If so, rename it.

  14. Josh
    Member
    Posted 7 months ago #

    @ esmi,

    Thank you. So taking a snippet of the code above for example purposes:

    wp_list_categories('child_of='.get_category_id('A').'&title

    It seems to me the browser would get confused on where to begin and end the groupings. Again, I'm no programmer :)

  15. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    The browser never "sees" that code. It's PHP and parsed before sending the resulting HTML to the browser.

  16. Josh
    Member
    Posted 7 months ago #

    I'm sorry, I meant the server. I just need to go back to PHP101 and study the details about single and double quotes.

    Thanks for your time :)

  17. jgrietveld
    Member
    Posted 7 months ago #

    I came across a the WordPress native function for retrieving a category's ID by it's name:

    get_cat_ID()

    So I've completely removed the custom function get_category_id(). Yet the error still occurs.

    To see if it has anything to do with that function, I've just removed that function completely and looked up the ID for each category manually. So my template now uses this function and arguments:

    <?php wp_list_categories('child_of=4&title_li=<h2 class="authors_index">A</h2>&show_count=1&show_option_none=<span class="no_quotes">No quotes</span>'); ?>

    But I'm still seeing the error messages...

  18. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    I'm sorry, I meant the server.

    @Josh: If you use single quotes for both and mix them within PHP code, you need to escape the HTML single quotes using \. That said, I tend to use single quotes for PHP and double quotes for HTML, too. Just wanted to make the point that you can use both types in PHP & HTML.

    So I've completely removed the custom function get_category_id(). Yet the error still occurs.

    @jgrietveld: So are you now using the native get_category function?

  19. jgrietveld
    Member
    Posted 7 months ago #

    The only function I am now using is the native wp_list_categories() function

  20. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    So what about the child_of='.get_category_id('A') in wp_list_categories?

  21. jgrietveld
    Member
    Posted 7 months ago #

    Not my previous message but in the one before I'm showing what I have now. I've completely removed that function and replaced it with the category id. So that custom function does not exist anymore in the theme.

  22. esmi
    Theme Diva & Forum Moderator
    Posted 7 months ago #

    Try:

    <?php wp_list_categories('child_of=4&title_li=<h2 class="authors_index">A</h2>&show_count=1&show_option_none=No quotes');?>

  23. jgrietveld
    Member
    Posted 7 months ago #

    Hi esmi,

    I think you were put on the wrong foot by the discusion on the single or double quotations. This has nothing to do with the issue.

    I've been testing all the arguments in the wp_list_categories() function to see what is causing it. As it turns out, the problem is caused by the 'show_count=1' argument.

    I can even safely run this function 2 times on a page without any issues. The error messages appear when I use this function 3 times or more.

    It seems that quite a few websites are experiencing this issue, so I think there might be a bug in the core file taxonomy.php.

    Does anyone have a clue what could be triggering this? For now the simplest solution is to just turn off the post count per category however that's far from ideal.

Reply

You must log in to post.

About this Topic