If you’d use the get_categories() function to get all the categories, you can then loop through them. Partial pseudo code, but this will do the trick:
$categories = get_categories( array() );
$colors = array();
foreach ( $categories as $category ) {
$cat_meta = get_option( 'meta_field_' . $category->slug );
if (isset($cat_meta['color'])){
$colors[ $category->term_id ] = $cat_meta['color'];
}
}
PS. I don’t know if the field in the options table is using the slug or the category id. The colors array will be filled with id’s of the category as key and value of the meta field as value.
PPS. get_categories()
function call might need some extra parameters in the array, adjust to your liking using the available parameters.
PPPS. While my answer technically answers this question, this answer by s_ha_dum is actually a better approach (might require some more refactoring though).
Related Posts:
- Individual Widgets per Page
- ‘Preview Changes’ for custom meta boxes?
- Using TinyMce with textareas in meta boxes on custom post types
- add meta box – custom field : which to choose?
- Add metabox to document tab in gutenberg
- How to add add_meta_box to specific Page Template?
- Adding another state (spam, reject, approve) to wordpress comments?
- How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
- extend Meta Box / Document Panel
- Add custom option to Standard Page Attributes Meta Box
- Only show metabox when date-value in other metabox is over?
- Populating meta box with select-list of existing posts, and assigning it to custom post types
- Create meta boxes that don’t show in custom fields
- How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
- TinyMCE in Custom Metabox not loaded after upgrading from WP 3.1.4 to WP 3.2
- wp_editor in add_meta_boxes does not show gallery
- How do I assign this filter to a variable? (Appending php & markup to the_content)
- Problem with adding exta field in metabox in custom post type
- Adding a custom field or metabox to the post-thumbnail widget?
- How do I add custom_meta_box_id’s value?
- add meta box using function.php
- Metabox image upload and custom field
- all tincymce’s switch when updating page after changing from html to text in custom metabox
- My metabox class
- How to construct multiple meta boxes
- Loading scripts to the Post Edit page only
- Force hide custom field metaboxes
- Woocommerce with metabox plugin
- How to Display Custom Meta Box only on Specific Page IDs
- Metabox will not save
- How to check for specific meta box value on front end and output accordingly
- How Meta Data is different from Custom Fields of POST/PAGE in WordPress
- Tweak Meta for Post to work it for Pages also
- custom field not saved
- How to create a Custom Meta Box with Name/Value Admin User Input Fields?
- Create Multiple File Upload Metabox in WordPress
- Users Select inside custom metabox
- Custom Metabox Not Saving
- Better Method for Multiple Meta Boxes
- Should custom meta boxes be able to output shortcodes the same as WordPress’ native post editor?
- Unsaved changes in metabox inputs not detected in the block editor
- Custom Meta Box (SELECT) Not Saving
- Get updated meta value after post update or published (custom post type) using hook
- Button inside Custom Meta Box triggering the Update Button
- Why is my Custom Meta Box Field Inputs NOT saving?
- custom-meta-box checkboxes from loop won’t save
- I need a “Choose from existing content” popin
- Outputing a metabox textarea and avoid line breaks inside li tags
- How can you include custom post meta in search without calling each key?
- shortcode in a custom metabox
- Specific coditional usage [closed]
- Set checkbox as checked by default in a metabox
- Problem with saving large amount of data in postmeta/usermeta
- Move Title and the Content WYSIWYG editor position
- How can I hide custom field from users used for caching response from external api?
- How to use media upload on metabox post page without breaking TinyMCE?
- Displaying Meta-Box Data Properly
- Let’s Create Custom Field Template Documentation
- Can I save post meta programatically without setting metaboxes?
- Meta box values are displayed on Custom Fields list. Is it possible to hide them?
- If metabox has content display content
- Custom meta boxes not saving
- HM CMB: Role Select
- Custom metabox not working
- Trying to implement AJAX into my admin pages. Am I improperly enqueue and localizing my scripts?
- How to store meta field values
- How to Convert Custom Fields from Text to Array?
- WP E-Commerce Custom Meta > Serialized array
- Make separate text boxes for separate WordPress Custom Fields
- show a specific metabox dependent on the page template
- Making custom meta box required (with error message if not filled in) on Gutenberg
- HTML for adding a meta box (basic text field) to page editor?
- Set class if a meta value is set within post archive
- Adding text box with add_meta_box
- Using Customizer API vs Custom Meta Box for custom content
- How can I ‘check’ the “custom fields” box from the Screen Options?
- Allow HTML in Custom Metabox area
- Metabox/Custom fields are not saving input data
- Custom field metabox not showing in back-end
- WordPress admin area: select box with 12.000+ options
- How to display selected option from dropdown list in a metabox
- Save, update, get and sanitize post meta as HTML not plain
- Update custom table on metabox POST
- Metabox value for post loop?
- how to modify a field’s size in a metabox : ROWS height, and scroll control?
- Append custom field items to content from plugin
- When post is updated, custom metadata in text area field is overwritten
- Call the latest posts from a custom field group to be displayed on front-page
- Custom Meta Boxes and Fields for WordPress: Change directory upload based on user-edit page
- How to add an option to admin to add image that could be used as header?
- Can i categorise my meta box?
- Custom Metaboxes, multiple post selection
- added a meta box to post however when saving menu while debug on throws a warning
- When editing a post with a custom meta box the values aren’t displaying correctly
- Use Metabox to enter Post Title
- Include custom fields into the content of a regular page
- How to get the value of particular get $meta value in wordpress
- Display custom field value into content with hyperlink
- How to add new Metadata options (Date, Author, etc.) for Posts?
- Saving multiple custom meta box fields