• Resolved benstewart

    (@benstewart)


    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

    https://www.ads-software.com/extend/plugins/category-icons/

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author TheSubmarine

    (@submarine)

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

    Thread Starter benstewart

    (@benstewart)

    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.

    Plugin Author TheSubmarine

    (@submarine)

    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;
    }

    Plugin Author TheSubmarine

    (@submarine)

    Still no response, I assume it worked.

    Thread Starter benstewart

    (@benstewart)

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

    Where am I replacing that code?

    Plugin Author TheSubmarine

    (@submarine)

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

    Thread Starter benstewart

    (@benstewart)

    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.

    Plugin Author TheSubmarine

    (@submarine)

    Thanks !

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Category Icons] Cannot define cat ID in get_cat_icon function’ is closed to new replies.