Create a gist now

Instantly share code, notes, and snippets.

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