WordPress.org

Support

Support » Requests and Feedback » is_category() ISSUE & REQUEST

is_category() ISSUE & REQUEST

  • I am experiencing an issue with two categories:

    Name: 3-d
    slug: 3-d
    id: 42

    Name: Illustration-folio
    slug: illustration-folio
    id: 3

    When I am on a category archive page and ‘3-d’ is the category, ‘is_category(42)’ and ‘is_category(3)’ evaluate to true.

    It would be nice to have separate functions for the type of category information being entered. For example, a function that only takes the category id. Or be able to accept arguments.

    If my issue is a result of me doing something incorrectly, please let me know.

    Thanks,
    Jordan

Viewing 3 replies - 1 through 3 (of 3 total)
  • function is_category ($category = '')
     {
         ...
          if ( in_array( $cat_obj->term_id, $category ) )
              return true;
          elseif ( in_array( $cat_obj->name, $category ) )
              return true;
          elseif ( in_array( $cat_obj->slug, $category ) )
              return true;
          ...
      }

    What I believe is happening is that when cat_id ‘3’ is not found in ’42’ it looks for ‘3’ in the current category name. Since it only looks for 3 anywhere in the $category variable, it finds 3 in 3-d evaluates this to true.

    I will look into this. Does anyone have suggestions?

    Thanks,
    Jordan

    This is also an inconvenience when you use is_category(cat_name) for a category name that shares a string with a similar category name. For example.

    using is_category(‘category’) evaluates to true when on the archive page having ‘category12’ as its name.

    can check for both:

    if(is_category($cat_name) && is_category($cat_id)){
        ...
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘is_category() ISSUE & REQUEST’ is closed to new replies.