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
- Opinions and recommendations on the best barebones base theme [closed]
- Different template of products for specific category. WooCommerce
- WordPress 5 / Gutenberg – theme doesn’t have featured image option showing up
- How to refresh WordPress Customizer panel upon entering a value
- Set Featured Image for Archive templates
- How do I change Twenty Nineteen’s primary color without using the color slider in the theme customizer?
- How to add the main style.css to my index.php?
- Remove action within a class in a parent theme from the child theme
- How to move WordPress theme files into a subfolder without breaking the theme?
- WordPress site migration addvice
- WordPress can’t see symlinked theme in Ubuntu
- adding multiple sidebars on pages
- Varying Search Result Pages
- Add js into a theme [closed]
- .htaccess edits
- Broken link to theme asset after restoring backup
- Create more than one section in Theme Customizer
- Get name of current page template in Gutenberg era
- Efficiency of wp_options vs a new table
- Should I implement my own custom theme
- How can I manually activate my previous theme without browser access to dashboard?
- Advantages of wordpress theme vs wordpress as a backend only [closed]
- Creating custom meta box throws PHP warning error in WordPress
- What is the point of needing add_theme_support( ‘html5’) in WordPress 5.x
- Plugin and themes are adding the same stylesheets
- WordPress EduPress and businessbite Theme Installation Failed [closed]
- Implementation of language_attributes function
- my blog crashes ie7?
- Setting Multiple Post Containers Across Homepage And Costumize Them
- Remove Read More Buttons
- wordpress theme link url
- Work on theme files on a server & browser preview before installing it
- div having different appearances in different themes
- wordpress template page Usage [duplicate]
- How to make a website like the ones in theme demos? [closed]
- Divi theme including javascript
- Remove ALL HTML from single page
- Remove Google Fonts from parent theme within a child theme [closed]