Like Ash was saying, something like this using $_REQUEST or $_POST will do it.
<?php
$args['exclude'] = "12,20"; // omit these two categories
$categories = get_categories($args);
?>
<select class="selectpicker btn-block" name="coupon_cat" id="category">
<option value="">Категори Сонгох</option> <!-- if nothing else is selected, this will be selected automatically -->
<?php foreach($categories as $category): ?>
<?php $selected = (isset($_REQUEST['coupon_cat']) && $_REQUEST['coupon_cat'] == $category->term_id)?'selected="selected"':''; ?>
<option value="<?php echo $category->term_id;?>" <?php echo $selected ?>><?php echo $category->name; ?></option>
<?php endforeach; ?>
</select>
Related Posts:
- Saving two categories from two dropdowns in front end posting form
- Additional form options based on category selected not working
- Exclude category from drop down list form
- How can I make post fields required in WordPress?
- Dropdown with category selection
- Get id of category from drop down menu
- How to add HTML5 ‘required’ attribute to wp_dropdown_categories() without JavaScripts?
- exclude category from WordPress Form function
- Help with multiple dropdown tags search
- Remove ‘rel’ attributes from the_category() output
- How to use wp_category_checklist()?
- wp_dropdown_categories and custom taxonomy + custom post type
- How to provide value for ‘selected’ on wp_dropdown_categories() for ‘multiple’ options
- wp_dropdown_categories() scripts working erratically on sidebar
- How to use an array of categories as a dropdown?
- How do I display only two categories Instead of displaying all categories
- Dropdown Categories used in form shows no results when all is selected
- Trying to get variables in hacked category dropdown
- wp_list_categories walker without links on categories that have subcategories (to make a nested dropdown menu)
- Filter posts by categories ajax is showing nothing
- WordPress Customizer: Dropdown with Category output
- Filter By Category Dropdown List With Custom Taxonomies
- A dropdown with checklist
- Search form options group categories
- Redirect depending on category chosen
- Wp Dropdown Category Not Show Current As Title
- wp_dropdown_categories initial value
- Trying to get categories and sub-category listing
- Get_term_meta() always returns false
- Woocommerce Category Sort Dropdown
- How to add custom option to wp_dropdown_categories?
- Default URL for category dropdown select option
- custom browse by
- wp_category_checklist won’t show up for non-admin users
- Get category fixed in dropdown browse categories
- Categories dropdown with all values selected using wp_dropdown_categories
- add custom option to get_categories dropdown
- Taxonomy for custom post type not found
- Ajax call activate after submit in edit-tags.php page
- Form Value of drop down category + Translation of ‘show option none’
- Categories as selectable links on submission form
- Fetch Post Category
- Conditional statement: if is_category, append at the end of page
- Category names dependent on each other?
- Tag Menu items based on their categories
- How to Manage and link certain custom taxonomy?
- Store All Post Categories In Array
- How to add an “All” category to the tag cloud?
- Question About Messing With Category Pages and Descriptions
- how to get postmeta info based on multiple categories?
- Change single.php template based on parent category
- Accessible Subcategory URL’s pages without using .php hack
- WordPress and “pretty permalink”
- How to show the posts of some category first, and then the rest? Cant figure out the coding
- How to relocate images
- How to display total views of all posts of one category?
- Category next page link not working
- Custom file with special code of category widget
- How to display the past events in one of the category?
- create post with main category and other categories from admin panel
- Custom field picture instead of post thumbnail on category page
- Get the categorie name of Event Organiser plugin [closed]
- How to display get_categories selected category?
- How Can Hide Define Category in Post Contents?
- How to auto update post title and slug with category name when post status is updated
- How to Query the Top 5 Posts of a specific category?
- get_the_terms_list output last child only
- Exclude posts with certain tags in category archive
- Hide category name using mod_rewrite
- Setting category for post as default
- Show One Level Category id
- Category page shows only 1 post when that post has more than 1 category?
- Assign a category to all articles
- Loop doesn’t work
- the_content() not showing full posts in category template
- Getting Post Tags From Certain Categories
- Dynamically creating content on custom URL without getting 404
- Too many categories drastically slow down my website
- ACF Gallery with Media Categories – how do display categories and sort
- How to get posts from many categories using WP_Query
- Removin /page/2 from pagination
- Configure query with multiple categories in a custom order?
- Filtered post assigned to categories
- WordPress pagination not working because of subcategory
- Display List of Categories Within a Custom Taxonomy
- Outputting subcategory title AND items on Category page
- Jetpack Mobile Theme: when on smartphone on categories the theme suddenly changes to jetpack mobile theme even though it’s deactivated
- How to exclude category and post_tag taxonomy while displaying custom taxonomy?
- Use different file includes for single.php
- Dropdown switching subcategories portfolio
- Hide category name in URL
- in_category(‘category-sluga’) returns true for Archive page of Category ‘category-slugb’
- How to get related category/categories in WordPress archive page
- How to show posts only for the last subcategory?
- New Category – custom taxonomy
- Category archives
- Category For Pages In WordPress
- Inserting categories as a hierarchical terms from frontend form
- Display Taxonomies in loop with template args
- Is it possible to query the result of a query?