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_post_meta as a list for drop down search filter

First, you have a very basic PHP mistake: single quotes mean “string literal”. Variables won’t be processed. You are literally putting “$variable” into the generated code.

Second, look at the third parameter of get_post_meta()

$single (boolean) (optional)
If set to true then the function will
return a single result, as a string. If false, or not set, then the
function returns an array of the custom fields. This may not be
intuitive in the context of serialized arrays. If you fetch a
serialized array with this method you want $single to be true to
actually get an unserialized array back. If you pass in false, or
leave it out, you will have an array of one, and the value at index 0
will be the serialized string.
Default: false

You are asking for a single variable as a string, and are then trying to iterate over it as if it were an array. I am surprised you aren’t getting errors. (see: https://wordpress.stackexchange.com/a/95983/21376)

It looks to me like you need to drop that third parameter or set it to false (the default), which will return an array that you can iterate over.

Related Posts:

  1. Save meta data with post, Without using any plugin [closed]
  2. Passing error/warning messages from a meta box to “admin_notices”
  3. Add “upload media” button in meta box field
  4. get registered metaboxes by post type or post ID
  5. How to get meta box data to display on a page
  6. esc before saving or before displaying does it matter?
  7. Add a meta description to home page?
  8. Check if meta key value already exists
  9. get_post_meta doesn’t work
  10. Metabox of one post influence setting on other
  11. How to store multiple input values with same meta_key
  12. Consolidate Metaboxes into 1 Big Metabox
  13. unable to save post meta on single field with multiple selects
  14. metabox upload file
  15. Why is variable value emptry in $_POST but available in $_REQUEST?
  16. Displaying Metabox value (custom post type taxonomy)
  17. Why does get_post_meta not work with the posts page?
  18. How to get meta box values – WP tuts tutorial
  19. Change the post date from a meta box
  20. update_post_meta and get_post_meta not working
  21. Repeatable custom meta fields
  22. how to save multiple checkboxes value in wordpress dynamically
  23. Using WYSIWYG In custom meta boxes
  24. Multiplicate entry on update_post_meta
  25. Undefined index error in custom post metabox
  26. Custom Meta box only returns most recent value on page
  27. How to prevent further updates of custom meta when using actions to set one meta based on another
  28. How to create a button click counter meta box?
  29. meta box & callback function
  30. $_GET & $post_ID
  31. Parse a text area custom meta box and assign as value to existing meta keys
  32. Getting metabox value?
  33. Hide Page Title with Post Meta
  34. How many meta-query fields support WordPress search at a time?
  35. How to check specific value in two metabox?
  36. Editor meta box Showing but not saving
  37. How can i get multi checkboxes value in metbox?
  38. WP_Meta_Query object with conditionals
  39. Show value of select dropdown in meta box
  40. remove a single post_meta
  41. Echo 2 values from one key in Array with get_post_custom
  42. save radio button selection in post-meta on submit
  43. post meta – problem : copy the same meta for all the articles
  44. Custom Meta Data is not being saved
  45. How using the Meta Box plugin, to filter posts by the value of a post type field?
  46. I can not display meta value in extras.php and template-tags.php
  47. How to improve my non-unique metadata MySQL entries?
  48. Update Post Meta in Front End with a form
  49. Update Post meta with custom variable
  50. get_post_meta not working on my custom-function page
  51. update_post_meta doesn’t work
  52. Saving custom fields for WP_Query to retrieve
  53. How to show all the associated posts with specific date of data metabox?
  54. Removing Meta Generator
  55. Only allow one meta key value per post in a category
  56. use post meta in add_meta_boxes action
  57. Custom meta box not saving values of radio buttons in WordPress
  58. Can’t save drop down select date in meta boxes
  59. update_post_meta does not work
  60. add_post_meta not saved
  61. when saveing $meta_box i get Undefined index error
  62. Updating post meta and Meta Box plugin
  63. Related posts and custom meta_box?
  64. Select Options Meta Data is Not Updating in Edit Meta Box
  65. How to display meta box data using “Meta boxes as needed”
  66. Metadata in loops
  67. Allow iframe in custom meta box
  68. Calling Data from Custom Meta Box
  69. How can i remove blank area caused by theme’s post meta boxes?
  70. How we insert values into database using metabox WordPress?
  71. Datepicker altField and altFormat to save a new meta key/value in a post?
  72. My meta box don’t want to save value
  73. CPT posts in drop downed in meta box on page doesn’t return post ID
  74. Create more Meta Boxes as needed
  75. meta_query with meta values as serialize arrays
  76. Set Default Admin Screen options & Metabox Order
  77. How to set default screen options?
  78. Add a Meta Box for uploading a SECOND Featured Image?
  79. Does WordPress have a “Form API”?
  80. Metabox with checkbox is not updating
  81. How to HIDE everything in PUBLISH metabox except Move to Trash & PUBLISH button
  82. What is the “Advanced” $context in add_meta_box?
  83. Use REGEXP in WP_Query meta_query key
  84. Removing panels (meta boxes) in the Block Editor
  85. Change The Title Of a Meta Box
  86. What is the index [0] for on post meta fields?
  87. WordPress SEO by Yoast: Hide Meta Boxes in Posts for Non-admins
  88. How to make open/closed and hidden/shown metaboxes status saved on a per-post basis?
  89. How To Remove The “+ Add New Category” Link From A Category Metabox
  90. How can I create a taxonomy meta-box with search suggestions but no new terms input?
  91. Remove the Featured Image Meta Box
  92. Remove the Yoast SEO Post Metabox [closed]
  93. Best practices for meta box placement?
  94. Creating a metabox to upload multiple images
  95. How Does WordPress Remember Metabox Positions?
  96. Sample code for validating custom metabox?
  97. Post custom metabox textarea using wp_editor
  98. How to Add Reminders/Notes to New Post Meta Boxes
  99. How do I get attachment_id?
  100. Removing Metabox for “Slug” without removing functionality
Categories metabox Tags meta-query, metabox, post-meta
While loop with bootstrap [closed]
Create a shortcode to use in visual editor

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