Skip to content

Instantly share code, notes, and snippets.

@versluis
Created October 8, 2013 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save versluis/6884992 to your computer and use it in GitHub Desktop.
Save versluis/6884992 to your computer and use it in GitHub Desktop.
adding categories to P2
<select name="drop_cat" id="drop_cat">
<option value=""><?php echo esc_attr(__('Select a Category', 'p2' )); ?></option>
<?php
$args = array (
'type' => 'post',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => false
);
$categories = get_categories($args);
foreach ($categories as $cat) {
$option = '<option value="'.$cat->category_nicename.'">';
$option .= $cat->cat_name;
// show how many posts there are in each category
// $option .= ' ('.$cat->category_count.')';
$option .= '</option>';
echo $option;
}
?>
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment