Support » Fixing WordPress » get_category($cat) returns NULL in widget

  • Resolved Nic Windley



    I’ve been using the following code in a sidebar without any problems;

    <?php if (is_front_page() || !is_single() || is_category()) :
    $this_category = get_category($cat);
    echo"<li><h3>Sub Categories</h3>";
    endif; ?>

    Works perfectly thanks to the advice on the forums.

    However if I move the code to a Widget which has PHP parsing enabled (have tried different plugins for this) everything works except get_category($cat) which does not return the current category ID, just null ?

    Any ideas how to get this working in a widget ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • OK, I initially thought that this was a widget problem but it turns out to be a problem with one particular site installation.

    No matter whether I use the above code get_category($cat) it keeps returning null, where as the other sites are fine.

    Can anybody advise why this would happen – is it a themes problem ?

    Have alerady replace all the wordpress files with a fresh download upgrade copy so it has to be a theme, settings and plugin problem.

    turns out that it was a wordpress issue but I had also made some change to the code above will testing and did not revert it back after reuploading the wordpress files

    everything is working just fine now!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_category($cat) returns NULL in widget’ is closed to new replies.