WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Nic Windley
    Member
    Posted 5 years ago #

    Hello,

    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>";
    echo"<ul>";
    wp_list_categories('orderby=order&amp;show_count=1&amp;depth=1&amp;title_li=&amp;use_desc_for_title=1&amp;child_of='.$this_category2->cat_ID);
    echo"</ul></li>";
    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
    Member
    Posted 5 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
    Member
    Posted 5 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