[resolved] get_category($cat) returns NULL in widget (3 posts)

  1. Nic Windley
    Posted 7 years ago #


    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 ?

  2. Nic Windley
    Posted 7 years ago #

    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.

  3. Nic Windley
    Posted 7 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic