WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Category Array Problem (3 posts)

  1. ghostpool
    Member
    Posted 4 years ago #

    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 } ?>
  2. s_ha_dum
    Member
    Posted 4 years ago #

    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
    )
  3. ghostpool
    Member
    Posted 4 years ago #

    Works like a charm. Thanks very much apljdi. :)

Topic Closed

This topic has been closed to new replies.

About this Topic