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:
- Custom field/meta populated by dropdown of existing posts?
- What is the index [0] for on post meta fields?
- Individual Widgets per Page
- Gutenberg add a custom metabox to default blocks
- ‘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?
- Custom field metabox not showing in back-end
- How to hide meta box values from custom fields list?
- Adding another state (spam, reject, approve) to wordpress comments?
- Arrange custom fields with drag and drop?
- How can I avoid re-inventing the Custom Fields wheel in my Plugin’s Metabox?
- Unable to get Preview of Uploaded image within a Custom Meta box
- Using media-upload.php to upload mp3 via custom fields
- extend Meta Box / Document Panel
- Add custom option to Standard Page Attributes Meta Box
- How to store the value of a custom field dropdown select for post referencing?
- Add multiple images to a page sidebar
- Only show metabox when date-value in other metabox is over?
- Custom Meta Boxes: Store two values in one repeatable field
- 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?
- How to load php file for specific page in admin?
- How to set default metaboxes on user creation?
- Metabox nonce PHP notice
- 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 in custom meta boxes
- Multiplile values checkbox or select in custom meta box
- Create custom field key upon theme activation
- Problem with adding exta field in metabox in custom post type
- Adding a custom field or metabox to the post-thumbnail widget?
- Custom fields to save multiple values
- How do I add custom_meta_box_id’s value?
- Undefined index error when saving content on metabox
- Gutenberg add a custom metabox to default blocks
- 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?
- Move the metaboxes to the very top of post editor
- How to improve my non-unique metadata MySQL entries?
- Set class if a meta value is set within post archive
- Adding text box with add_meta_box
- Add forms dynamically in admin pages?
- WordPress Blocks, setAttributes not saving
- Using Customizer API vs Custom Meta Box for custom content
- non-unique #_ajax_nonce id in browser console
- 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
- add meta box considers the selected option as post parent
- Custom field metabox not showing in back-end
- Issue on Creating Checkbox Field On Custom Post type
- WordPress admin area: select box with 12.000+ options
- How do I display a custom field in an existing form on the front end?
- How to display selected option from dropdown list in a metabox
- Save, update, get and sanitize post meta as HTML not plain
- Why does this javascript search function in the WordPress Admin not work?
- get wordpress post loop by meta box date
- Create Meta boxes dynamically
- Update custom table on metabox POST
- Sub Field of File Field
- Save input form on custom field
- Metabox value for post loop?
- how to modify a field’s size in a metabox : ROWS height, and scroll control?
- If metabox fields has content display content
- I have a form with a custom button ,i want to add the field data to an database when clicking the custom button
- Append custom field items to content from plugin
- Get meta value when the page is a blog archive
- Can’t save meta field value if the title not set
- Display Data From This Custom Media Upload Meta Box?
- 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?
- wp_postmeta are updated for only one page
- My meta boxes update wp_postmeta of posts but not of pages. What is wrong with the code?
- Meta Box Data added to header redirect
- Can i categorise my meta box?
- Custom metaboxes not saving after switching themes
- Custom Metaboxes, multiple post selection
- I want my post to republish again after adding a custom field
- 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
- Get fields from metabox array
- Creating an If/Else statement using WPAlchemy MetaBox radio boxs
- How to get the value of particular get $meta value in wordpress
- Display custom field value into content with hyperlink
- Using CMB2 Plugin to create text_date metabox (datepicker) How do I save multiple dates? [closed]
- Dynamic background image used in css after selector
- Add fields to edit in custom widget
- How to add new Metadata options (Date, Author, etc.) for Posts?
- Saving multiple custom meta box fields
- Custom fields empty after refreshing page
- doesn’t save custom meta box data wordpress