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
- Activate Gutenberg in category-descriptions
- How to show subcategories in categories else show posts
- How would I increase the Author Role to be able to add a new category?
- How to remove the parentheses from the category widget
- Only show category to certain user levels without plugin
- How to: 301 Redirect /category/ to /customname/
- Custom Query to search through categories
- Get sticky post from category?
- Display one latest post from multiple categories
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- Update taxonomy value of post type in query
- Is it possible to add short code and html tag in Category Description?
- How do I specify more than one category?
- Set post categories to include parents when setting child category
- Making a tourism information website [closed]
- Adding Categories Through Function
- WordPress search only showing a few posts
- How to recreate a copy of a product category in WooCommerce? [closed]
- Multiple category archive page
- List subcategories of active parent category (WooCommerce)
- How to display post type and category links in foreach WordPress code
- Updating category template to change how subcategories display
- Add multiple classes. Different style for each category tag
- Inside a loop, how to change CSS class based on category name?
- Randomly load categories with latest post
- Is it possible to remove from default category widget?
- WordPress alphabetical A-Z custom post type post result display
- Count category views – Is it possible?
- wp_dropdown_categories not showing option as selected
- How to check if a post belongs to a category that has only 1 posts?
- pages meta box – get_categories dropdown
- How do I use just one category’ posts on my home page?
- If x comments in a post move post to category y
- Count tags for a specific category
- How can I display tags as categories?
- Adding additional content on post depending on post categories
- wp_list_categories not excluing multiple ids
- Custom meta boxes ID prefix showing on first category but not others
- Exclude category from foreach loop
- ID of last created category
- Get categories of queried posts
- Limit Loop to One Category
- Different header for each category
- sidebar troubles, taxonomy trouble
- Code for Category, Tags, Archive URLs
- Duplicate new categories across multisite network
- Display all subcategories from parent category
- How to show WooCommerce Categories on ‘shop’ page instead of products?
- How to create Child Category page from scratch at wordpress?
- How to insert category to post via php?
- Show Subcategory Name Instead of Parent Category
- Get category id of next / prev post inside the_post_navigation
- Limit Category/Tag Dropdown To blog_id in Multisite Install With Global Categories/Tags
- Multiple Dropdown’s with Submit Button
- Media Library filter returns undefined function get_current_screen
- Custom built theme won’t filter categories
- get IDs from links categories
- Form validation on user profile edit
- Narrow Down a Shop Page Results Based on a Product Tag in WooCommerce