Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

get Custom field label (select/dropdown) on front end

You can set the keys of the array to be user-friendly, but more appropriate would be to define the options array in a function, and then use that function in both the backend and frontend (untested):

Array

function product_condition_array() {
    return array(
        'new'            => __( 'New', 'woocommerce' ),
        'like_new'       => __( 'New other (see description) ', 'woocommerce' ),
        'remanufactured' => __( 'Remanufactured', 'woocommerce' ),
        'used'           => __( 'Used', 'woocommerce' ),
    );
}

Backend

woocommerce_wp_select(
    array(
        'id'          => '_condition',
        'label'       => __( 'Condition', 'woocommerce' ),
        'desc_tip'    => true,
        'description' => __( 'Part Condition.', 'woocommerce' ),
        'options'     => product_condition_array(),
    )
);

Frontend

$condition = get_post_meta( … );
$conditions = product_condition_array();
$condition_display = __( 'Unknown', 'woocommerce' );

if ( array_key_exists( $condition, $conditions ) ) {
    $condition_display = $conditions[ $condition ];
}

echo esc_html( $condition_display );

This has the benefit of a single location used by both backend and frontend, so changes are reflected immediately in both locations, simplifying future changes.

Related Posts:

  1. How to break meta values into different items and avoid duplicates?
  2. How to wrap meta values seperated by comma in ? [closed]
  3. Run a check for multiple meta key values
  4. IF Custom field value equals ZERO
  5. Update post meta custom field using block editor
  6. Set class if a meta value is set within post archive
  7. Custom Field: Display only if a specific key is selected outside the loop
  8. WP Query Args – search by meta_key or title
  9. Saving multiple custom meta box fields
  10. Block Editor – Meta values not saved, meta changes to empty array on update
  11. Custom post meta field effect on the performance on the post
  12. Difference between meta keys with _ and without _ [duplicate]
  13. Orderby meta_value only returns posts that have existing meta_key
  14. What is “meta_input” parameter in wp_insert_post() used for?
  15. How to enable revisions for post meta data?
  16. When using add_post_meta and update_post_meta, is there any way to give the individual arrays keys?
  17. Storing meta fields multiple times OR once with multi dimensional array?
  18. How can I display all values of a custom field from posts with a certain value of another custom field or from certain post types?
  19. passing argument to get_template_part() or a better way to code
  20. Is it possible to store arrays in a custom field?
  21. importing data from non-wordpress mysql db
  22. Assign/update the custom field value for all posts
  23. Create meta boxes that don’t show in custom fields
  24. Copying Custom Meta Values from existing post to a duplicate post
  25. WP_query : meta_key with custom rule for specific value
  26. Move value of one custom field to another
  27. Order posts according to user defined order for meta values?
  28. Displaying posts with only upcoming dates according their custom field date value
  29. Get a post_id where meta_value equals something in a serialized meta_value field
  30. How to save a ToggleControl value in a meta field?
  31. MySQL query to set wp_postmeta using term_taxonomy_id value
  32. How can I sort homepage by a meta value?
  33. Get specific custom field keys from a post and put into an array
  34. Bulk remove post meta
  35. Create Multiple File Upload Metabox in WordPress
  36. filtering custom post types via meta data drop down
  37. If meta key exists in get posts function otherwise create it
  38. Filter by custom field (meta_key) using JSON API
  39. WordPress Rest API to call page data associate with custom meta
  40. How do I Implement Atomic Update of Post Metadata?
  41. How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
  42. How do I have WP_Query match posts based on search parameter OR meta fields? (rather than search parameters AND meta fields)?
  43. Why is my Custom Meta Box Field Inputs NOT saving?
  44. Get registered custom fields or post meta even if empty
  45. Sort alphabetically by custom field
  46. get_posts in meta box dropdown not showing latest posts
  47. Limits, not all post are showen when querying for posts by view count
  48. Display Custom Meta Box Field Only If Value is Present
  49. Ordering posts by custom field named “date” in backend
  50. Stop sending email everytime I updates my post
  51. Best way to store everyday post views?
  52. pre_get_posts : only get posts by wp_usermeta value
  53. Custom meta is not being saved
  54. Branch made by several custom values
  55. Looping inside block return
  56. change order of images attached to post
  57. Sortable Custom Columns not sorting correct
  58. how can I show name and value of Custom Fields together?
  59. Can I save post meta programatically without setting metaboxes?
  60. Meta box values are displayed on Custom Fields list. Is it possible to hide them?
  61. Gravity Forms Update post meta from template [closed]
  62. Best way to achieve multiple links in a post title
  63. How can I add/update post meta in a admin menu page?
  64. Show array of meta_value in Edit Post Coloum
  65. custom filed from post in the side bar
  66. wordpress multi user question
  67. How to change text color depending on the number value (Using javascript)
  68. Making WP_Query limit results by date before today where date is a meta_query
  69. Adding Custom Metadata to my Archive/Posts page
  70. How to improve my non-unique metadata MySQL entries?
  71. Custom Fields Not Showing (ACF not installed)
  72. SQL query to change the value of a Custom Field
  73. Custom meta POST request fired twice when updating a post in Gutenberg
  74. Add custom field information to source meta data
  75. How do I update custom field post meta in frontend post template?
  76. How to Find List of Available Custom Fields for Theme?
  77. Create Shortcode shows only posts with custom_field meta
  78. Create Meta boxes dynamically
  79. Custom Fields Not Working In Footer
  80. ACF plugin and field update
  81. Delete custom meta
  82. Search one custom field?
  83. Can’t save meta field value if the title not set
  84. Adding custom fields to images
  85. How to save dynamically generated value in post type?
  86. wordpress simple post multi rating with post_meta and user_meta
  87. how to show this part only in the single post page?
  88. Display meta data from a custom field within plugin Category Grid View Gallery
  89. Custom fields / meta box output
  90. If post custom meta data is not set, show normal state
  91. Colecting values from custom field checkboxes and displaying them in the post
  92. Build Array from Input Fields question
  93. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  94. custom field with links
  95. How can i put a custom field inside this php
  96. Check for custom field value in different post type than current one and do something
  97. How to add new Metadata options (Date, Author, etc.) for Posts?
  98. Search for meta_query does not return any result if combined with title
  99. Can I count every article following extracted meta value?
  100. What is the best way to get a different post’s custom field/postmeta with js?
Categories custom-field Tags custom-field, meta-value, post-meta
Critical error after updating my wordpress
Request initiator chain contains old CDN

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress