• Resolved GhostPool

    (@ghostpool)


    I’m using the the following code for an is_category array, which works fine.

    <?php if(is_category(array(5,3,7))); ?>
    
    .....
    
    <?php } ?>

    However whenever I replace 5,3,7 with a php tag ($theme_cats) to reference some category IDs written exactly like 5,3,7 it doesn’t work. I know $theme_cats works and when I echo the tag it returns 5,3,7. I assume I need to call the array in another way, can anyone help?

    <?php if(is_category(array($theme_cats))); ?>
    
    .....
    
    <?php } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • So… array(5,3,7) is not the same as $theme_cats = "5,3,7"; array($theme_cats);. print_r() it and take a look.

    The former is:

    Array
    (
        [0] => 5
        [1] => 3
        [2] => 7
    )

    The latter is:

    Array
    (
        [0] => 5,3,7
    )

    What you want to do is explode the string into an array, like so: print_r(explode(',',$theme_cats)); Then you get this, which is what you want:

    Array
    (
        [0] => 5
        [1] => 3
        [2] => 7
    )
    Thread Starter GhostPool

    (@ghostpool)

    Works like a charm. Thanks very much apljdi. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Category Array Problem’ is closed to new replies.