WordPress.org

Ready to get started?Download WordPress

Forums

Category Icons
[resolved] Cannot define cat ID in get_cat_icon function (9 posts)

  1. benstewart
    Member
    Posted 1 year ago #

    I am getting this error any time I try to define a "cat" in the get_cat_icon function. The function is running inside the loop of my Archive template. It works fine if I do not include a "cat" option in the function call.

    Fatal error: [] operator not supported for strings in /htdocs/wp-content/plugins/category-icons/category_icons.php on line 117

    http://wordpress.org/extend/plugins/category-icons/

  2. submarine
    Member
    Plugin Author

    Posted 1 year ago #

    If you don't do that, for example :
    get_cat_icon('cat=3');
    could you paste your code, please ?

  3. benstewart
    Member
    Posted 1 year ago #

    Sure. I did:
    get_cat_icon('cat=118'); // FAILED!

    Then I did:
    get_cat_icon(); // SUCCESS!

    What I used to have (that used to work properly) was:
    echo get_cat_icon("max_icons=1&echo=0&link=0&small=false&cat=".$cat_id);

    In that case, the $cat_id variable was being retrieved dynamically by a get_the_category() call and then later a get_the_terms() call instead. But, to eliminate variables (no pun intended) I removed all of the extra options from my get_cat_icon() call and hard-coded the category ID in there. It still didn't work.

  4. submarine
    Member
    Plugin Author

    Posted 1 year ago #

    What happens if you replace :

    if (is_category() && in_the_loop()) {
    		$cat = (int) get_query_var('cat');
    		$category=get_category($cat);
    		$p['cat'][] = $category->cat_ID;
    }

    by:

    if (is_category() && in_the_loop()) { // Displays only the icon of the category page
    		$cat = (int) get_query_var('cat');
    		$category=get_category($cat);
    		if (!isset($p['cat'])) {
        			$p['cat']=array();
    		}
    	    	$p['cat'][] = $category->cat_ID;
    }
  5. submarine
    Member
    Plugin Author

    Posted 1 year ago #

    Still no response, I assume it worked.

  6. benstewart
    Member
    Posted 1 year ago #

    I have not had an opportunity to try it yet. Busy.

    Where am I replacing that code?

  7. submarine
    Member
    Plugin Author

    Posted 1 year ago #

    OK. In the category-icons.php file. just after this line :
    stripslaghes_gpc_arr($p);

  8. benstewart
    Member
    Posted 1 year ago #

    Just to be safe I actually did:

    if (!isset($p['cat']) || !is_array($p['cat'])) {
        $p['cat']=array();
    }

    It seems to have worked although I didn't go back through and change all of my code yet.

  9. submarine
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks !

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags