All post categories dropdown in WordPress

<selectname=”event-dropdown”onchange=’document.location.href=this.options[this.selectedIndex].value;’>
            <!–<option value=””><?php //echo esc_attr(__(‘Select Category’)); ?></option> –>

            <?php
                $option = ‘<option value=”‘ . get_option(‘home’) . ‘/category/”>All Categories</option>’; // change category to your custom page slug
                $categories = get_categories();
                foreach ($categories as $category) {
                    $option .= ‘<option value=”‘.get_option(‘home’).’/category/’.$category->slug.'”>’;
                    $option .= $category->cat_name;
                    //$option .= ‘ (‘.$category->category_count.’)’;
                    $option .= ‘</option>’;
                }
                echo $option;
            ?>
        </select>

Leave a Reply

Your email address will not be published. Required fields are marked *