Jump to content

help with array and loop


Recommended Posts

I am working with wordpress. I am using a plugin that gets options stored in an array in the database. This is how I get the options


$options = get_option('option_tree');
echo $options['exc_cat'];


the exc_cat is a key that stores a set of values. Right now with the code above, it echoes Array. If I do this


echo $options['exc_cat'][0];


it returns 5. Which is what I would expect it to do. What I can't figure out is how to get it to store each value which should be a number into 1 variable. What I need to do is loop through each value that is stored in the exc_cat key, return the number seperated by a -1,. So the result should look like this



-1, -5


1 and 5 should be the only two numbers stored in the array at this point. Can you help?



Link to comment
Share on other sites

well, I almost have it working. It removes one category but I think it is failing to remove the next one because of a trailing , It is returning




instead of -1, -5


foreach($options['exc_cat'] as $cat) {
   query_posts($query_string . '&cat=-' . $cat . ',');


This is the only way I could get it to remove the category. One still stays on the page.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.