WordPress – Advanced Category Excluder – Undefined Variable Error

Trying to use the Advanced Category Excluder plugin and everything works great except on my 404 page I’m getting all of these “Undefined variable” errors on line 446

Try it here:
http://bolivares.com/test

Read More

Line 446 reads return $filter;

In full context:

function ace_get_section()
{
    global $wp_query, $ace_targets;

    if (is_array($ace_targets))
    {
        foreach ($ace_targets as $key=>$val) 
        {
          if (!empty($wp_query->$key) && $wp_query->$key == 1) $filter = $key;              
        }
    }
    return $filter;
}

Plugin Page
http://wordpress.org/extend/plugins/advanced-category-excluder/

Anyone know how this can be resolved?

Related posts

Leave a Reply

1 comment

  1. That $filter variable is defined only when some conditions are met but when conditions are not met the variable is undefined as the notice says.

    So try to add $filter=""; in the beginning of the function like this:

    function ace_get_section()
    {
        global $wp_query, $ace_targets;
        $filter="";
    
        if (is_array($ace_targets))
        {
            foreach ($ace_targets as $key=>$val) 
            {
              if (!empty($wp_query->$key) && $wp_query->$key == 1) $filter = $key;              
            }
        }
        return $filter;
    }