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

Ordering posts by metadata

Try meta_value_num

'meta_key' => 'metadata1',
'orderby' => 'meta_value_num'

Add these 2 parameters to $args. This does the sorting considering metadata1 as numeric

Related Posts:

  1. Save metabox with multiple checkbox array
  2. get_posts() not working when accessing with a custom user role
  3. Saving value of a selection option in comment form as comment meta
  4. Run Shortcode of post’s custom field in functions.php / Plugin
  5. Delist entries in the_loop
  6. Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
  7. Any way to update_post_meta with html content? It gets stripped and becomes empty
  8. Displaying Custom Post Meta
  9. A better way of getting draft posts that has a particular post meta using get_posts function
  10. How can I add an image upload field directly to a custom write panel?
  11. Post meta vs separate database tables
  12. How do I improve this admin query snippet to avoid generating duplicate results on non-meta searches?
  13. How to return only certain fields using get_posts()
  14. How to validate custom fields in custom post type?
  15. How to add tab which is visible only in admin side of product in woocommerce? [closed]
  16. Creating custom field with drop down on new post page
  17. Why Does get_posts() Return an Empty Set?
  18. get_posts / WP_Query Memory size of 134217728 bytes exhausted
  19. Retrieving custom fields with $wpdb->get_results
  20. How to create Image gallery Metabox in wordpress [closed]
  21. Utilize TinyMCE hyperlink chooser outside of TinyMCE
  22. How to enable users to down-vote in this simple voting counter (that uses the post meta)?
  23. anything like add_meta_box for categories?
  24. template_redirect for single posts w/ custom fields
  25. Order posts according to user defined order for meta values?
  26. How can I free up the memory used by update_post_meta?
  27. Is there a way to list tags order by post_meta field
  28. Support auto-save and revisions for custom fields
  29. Best choice of options/settings framework for plugin/theme development
  30. Plugin development: get_post_meta is not working [closed]
  31. Act on user meta updated, but only once
  32. How to check if Woocommerce Order number equals to post ID?
  33. Adding set of custom fields to WordPress Post in Dashboard
  34. update post meta for checkbox in the admin when inserted in the front-end
  35. 403 Error when text is pasted in Custom Metabox Textarea
  36. Custom Taxonomy to dropdown box on adminside wordpress
  37. Create & Save multiple Meta-boxes
  38. If meta key exists in get posts function otherwise create it
  39. Add a Save Button to Custom Meta Box [duplicate]
  40. get post attachment using ajax
  41. Plugin with action ‘save_post’ needs to press publish twice on order to publish
  42. Strange issue saving custom field data for a WooCommerce order
  43. Woocommerce – Convert Delivery method into a custom field
  44. How to get Metabox custom field to show checked if value is updated using post meta query?
  45. How do I update a field of a meta box?
  46. Input value from metabox is not found in $_POST after post save
  47. Doubts about the use of metadata and how this can affect performance on WordPress
  48. update_post_meta not working in a loop
  49. Get draggable widgets on Edit Post page
  50. How to get post content by get_posts function?
  51. Custom code for WordPress dynamic menu
  52. Why does my widget break other widgets?
  53. get_posts in meta box dropdown not showing latest posts
  54. Custom fields for custom post type
  55. What’s wrong with this post__not_in argument?
  56. Checked() function on a multidimensional array
  57. What is the best way to store a few fields?
  58. Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working
  59. How can I add a simple custom field to my plugin?
  60. Ajax is not working in a loop
  61. WP nonce field checkbox prints checked=’checked’ outside input field
  62. Ajax: Populate with content from a post’s ID not working – duplicating current page html instead
  63. How to save post meta as an array in Gutenberg?
  64. per blog metadata for plugin
  65. How to format custom fields when editing an attachment?
  66. Using delete_post_meta for deleting multiple selected options
  67. Get audio metadata on file upload
  68. Plugin can’t be activated [closed]
  69. Remove Meta-boxes (Yoast SEO plugin) [duplicate]
  70. Is there a way to add a link with add_post_meta?
  71. Adjust query on single
  72. how to add custom fields into new & update post page?
  73. Customise Grouped Product display in Woocommerce with custom column
  74. Why is $_POST empty when saving custom Meta Box?
  75. Condition to check previous next article post title
  76. register_meta not showing custom post type metabox data in rest api
  77. WP_Query not ordering correctly
  78. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  79. Adding customs fields on each product on the cart
  80. Insert, update or remove data from database (usermeta)
  81. add_meta_box does not display meta box in Admin
  82. Unexpected issue when using attachment_fields_to_edit filter
  83. WordPress delete mysql rows with string
  84. How to get post that has non zero or greater than zero meta value
  85. Saving post meta
  86. How and when would I implement some code which would take data from one part of the Db and put it in another?
  87. Include add_post_meta in a plugin
  88. Custom query not working in plugin admin page
  89. How can i call from custom fields to the category editor?
  90. How do I query posts and have their related taxonomies returned in the results?
  91. I want to display the content of a text field only if it has been entered
  92. Create Unique and Customized User ID for Website Members in WordPress
  93. Can I log the searches that are returning 404 in the DB?
  94. filter on get_posts efficiently
  95. Custom fields in the billing address section woocommerce
  96. Add File field in WooCommerce Box office plugin
  97. Objective Best Practices for Plugin Development? [closed]
  98. add_menu_page() with different name for first submenu item
  99. Autoloading & Namespaces in WordPress Plugins & Themes: Can it Work?
  100. How to include PHP files in plugins the correct way
Categories plugin-development Tags custom-field, get-posts, plugin-development, post-meta
Can’t access wp-admin
What is the advantage of using header-catname.php over is_category(‘catname’);?

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