devinsays / options-framework-theme

An Options Panel Framework to help speed theme development.
http://wptheming.com/options-framework
GNU General Public License v2.0
754 stars 229 forks source link

how to get the keys from values = 1 from multicheck? #56

Closed naires closed 12 years ago

naires commented 12 years ago

Hi,

i have this:

// Pull all the categories into an array
$options_categories = array();
$options_categories_obj = get_categories();
foreach ($options_categories_obj as $category) {
    $options_categories[$category->cat_ID] = $category->cat_name;
}

$options[] = array(
    'name' => __('Select a Page', 'options_framework_theme'),
    'desc' => __('Select page to dislplay the categories checked bellow', 'options_framework_theme'),
    'id' => 'select_page',
    'type' => 'select',
    'options' => $options_pages);

After i made multiple checks in categories this is the array saved into wp-options:

Array ( [13] => 1 [7] => 1 [6] => 1 [23] => 0 [12] => 0 [5] => 0 [11] => 0 [22] => 0 [3] => 0 [14] => 0 [1] => 1 [17] => 0 [10] => 0 [18] => 1 )

and my question is:

13, 7, 6, 23, 12 etc are my blog category ids and what i need to know is how can i extract only the $category->cat_ID numbers/values checked = 1?

i have tried <?php echo implode(', ',of_get_option('check_categories' )); ?> but the result is 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 and i want 13,7,6,23 and 1, all the [values ]=1

Thanks, nelson

naires commented 12 years ago

i just solved it. it's quiet simple, that's why i'm a zero in coding :)

First use the array_keys to select only the keys with value 1: <?php $categories = of_get_option('check_categories' ); ?> <?ph array_keys($categories, 1); ?>

After put the function inside implode function to get the keys separated with commas like this:

<?php echo implode(', ',array_keys($categories, 1)); ?>

And the final result is:

13,7,6,1,18 this are the Category ID's that are multicheck in my options

natalasa commented 10 years ago

hai naires, can you help me, I want to show all category that selected using multicheck. and every category that show, have thumbnail image that was get from first post on that category. example I have 3 category, "kawasaki", "honda" and "yamaha". I select category at multicheck "honda" and "yamaha". So category that will show is "honda" and "yamaha" with thumbnail image from first post that have category "honda" and "yamaha". thanks