What you are looking for is the selected() function.
Your updated option should look like this:
<option
value="<?php echo $category->cat_ID; ?>"
<?php selected($option, $category->cat_ID); ?>>
<?php echo $category->cat_name; ?>
</option>
// EDIT
Oh, and BTW, in your particular case you might want to use the wp_dropdown_categories function, I guess.
That would be:
wp_dropdown_categories(
array(
'selected' => $option
// maybe some other settings
)
);
Related Posts:
- Best practices for a Style/CSS based theme options page?
- Passing dynamic options from backend to frontend
- How To Add New Option Types To Option Tree?
- How to use media upload on theme option page?
- How do I create my own admin button and theme settings page?
- Add a page outside of the current theme?
- Moving WordPress.com theme and widget settings to self-hosted site?
- Multisite: setting theme and options when a new blog is created
- Copying theme from Localhost to Live does not copy all theme settings with it?
- Register theme customizer settings when theme activates [duplicate]
- Switch Theme Through Options Panel
- How to make alert for new version on theme options?
- Add transparency to wordpress color picker?
- How can I show more than 15 themes at a time in the admin menu?
- How to go about pre generating css file with variables from theme options
- Is there a reliable way to keep track of how long a WordPress theme has been active?
- Does uninstalling a WordPress theme delete its database values?
- Cannot find the code for “Edit This” link in posts in a specific theme
- Defining different theme for Blog posts page
- Working with an Array inside Your Theme Options Array – Multiple Values
- How to set different settings for a mobile theme?
- Add a series of checkboxes to theme options
- Disable Theme API / Front end (for API only environment)
- What’s the proper way to include inlined javascript-source?
- How to understand a specific bit of WordPress syntax
- Should a child theme share the same theme options row as the parent, or should it have it’s own options row?
- What’s the order of loading wordpress elements?
- Creating a theme options page
- loss of theme options while site deployment in production
- Theme settings default, strange behavior before first save
- How Do I Use A Custom Mobile Theme?
- How to find out if page_for_posts is showing (in order to style menu item)
- New custom theme option (text input) giving index error
- How can I make some themes usable only by admins?
- Custom options below pages/posts editor?
- Redux callback action
- Full page (no WP admin menus and options) admin theme options
- Preserve theme settings when migrating from local to live
- Functions containing parameter ‘yourtheme’
- How to dynamically change theme’s slogan from admin?
- What is the “pub” theme? [closed]
- Problems to disable the comments for my statics pages
- Color Options from Theme Customizer API not returning via get_theme_mod()
- Issue with theme mod options during domain migration
- .PO file is found but I don’t see translations: how to debug the problem?
- How to add some php code in header.php using plugin
- WordPress activate theme error $pagenow
- Setting a new default template for the creation of a page
- WordPress setup one database with two different website?
- How to include stylesheet in custom admin using parent_slug
- Get data from Theme Options and use them into meta options field in custom post type
- Cannot update a file for my theme
- List of categories instead of dropdown menu selector in admin options
- What’s the easiest way of adding more options in the Theme Options of the twenty eleven theme?
- Switching among theme customizations
- How to implement theme option to change bootstrap 4 container from .container to .container-fluid
- how to create a section inside a section with theme options customizer
- Warning: call_user_func() expects parameter 1 to be a valid callback
- Can i add wordpress editor to my custom theme option? [closed]
- Create /archive page in WordPress Theme
- Theme Options Menu Item – Permission Issue
- Church hope them issue
- correct tags for validating input types
- Buddypress User Settings template location? [closed]
- How to code static pages in WordPress
- Theme, WordPress Version, MySQL Version, PHP Version Update affected files and folders
- Can “Classic Editor” plugin help to replicate the old website / theme development experience from c. 2011?
- How to display footer menus in wordpress
- Debugging in WordPress at Theme installation [duplicate]
- understanding theme hierarchy
- wp_enqueue_style $dep argument does nothing?
- Posts as filtered list – expandable
- Is it a good practice to disable wpautop for premium themes?
- Theme options are they necessary
- How to remove current theme customizations
- Create QuickStart Package for WordPress just like in Joomla
- After installing a free theme, my wordpress turns into text mode when accessing remotely
- why is this script not working on my site
- is theme network enabled?
- Pharmacare theme login page / login modal redirection to custom URL
- theme installation not working
- wordpress-theme 2017: featured image behaviour: where to set the height of the featured image?
- Changing a parent theme safely
- Trying to create a child theme with plugin
- Theme-based character encoding issue
- Linkedin not returning right info
- how to load rtl.css file before style.css [duplicate]
- CSS/JS is not working in multi lang installation
- Using Customizer value in an external PHP file inside a theme
- Theme stops media uploader from working
- Theme automatically inserting “more” tag on every post
- Create a live demo gallery for themes
- Page structure using The Customizer Api
- theme 2016 – customize css – nothing happens
- Installing themes from an external website [closed]
- Best Practice Jumbotron Image for WordPress ~ Responsive
- How to make a page extend full screen [closed]
- Should you directly edit Template Parts and Templates from themes?
- get_post_meta() doesn’t allow email
- How to change database entries due to theme change